Computing Foundations › The Command Line › Day 8
Day 8: Meet the Terminal: Shells, Prompts, and Commands
After this lesson you will be able to tell the terminal, the shell, and a command apart, read any command by its anatomy, describe the read-eval-print loop your shell runs, and use history, tab completion, and the manual to work quickly at the prompt.
Hands-on lab for this lesson
Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-008-meet-the-terminal-shells-prompts-and
- Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git cd ai-roadmap-365.github.io - Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
cd labs/sections/computing-foundations/day-008-meet-the-terminal-shells-prompts-and - Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
- Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
bash tests/run_tests.sh # or the test command named in the lab README
You can also open the lab as a local page (works offline, shows the file tree and expected output).
Learning objectives
By the end of this lesson you will be able to:
- Distinguish the terminal emulator, the shell, and a command, and identify which one actually interprets and runs your instructions
- Break any command line into its three kinds of word — the command, its options/flags, and its arguments
- Describe the shell's read-eval-print loop step by step, from typing a line to the prompt returning
- Name the common shells (bash, zsh, fish), start each one, and explain why macOS defaults to zsh while many Linux systems default to bash
- Use command history, tab completion, and man pages to run commands faster and look up options without memorising them
- Discover which shell you are running and what your prompt string is, using echo $0, echo $SHELL, ps -p $$, and echo "$PS1"
- Explain why automation, reproducibility, and remote control make the terminal the primary interface for serious computational work
Prerequisites
- A computer running macOS, Linux, or Windows with permission to open a terminal
- Days 1–7: a working mental model of how a computer runs programs (the terminal is how you will now drive it)
Why this matters
-
Every AI tool you will use is installed and run from a terminal. Frameworks, model servers, GPU diagnostics, deployment — all of it.
-
Every server you rent has no screen. The terminal is not a preference there; it is the only interface.
-
A command is shareable as text. That is why every README, every tutorial and every error report you will ever read speaks in commands.
-
This is Week 2, and it is the week that changes how you work. Last week explained the machine; this week you start driving it.
The idea in plain language
-
A terminal is a window that shows text and takes typing. That is all it is.
-
A shell is the program running inside it that reads what you type and does something about it.
-
You name what you want instead of pointing at it.
-
Everything you type is one of three things: a command, an option that changes how it behaves, or an argument naming what it acts on.
-
Learn to read that structure and no command ever looks alien again.
Historical background
-
Before screens there were teletypes — printing terminals that typed the computer’s replies onto paper, one line at a time.
-
The line-at-a-time interface survived the paper. When screens arrived they emulated the teletype, which is why the program is still called a terminal emulator today.
-
The shell was deliberately separated from the kernel in early Unix, so it could be replaced. It is an ordinary program with no special privileges.
-
That decision is why shells compete. The Bourne shell, then bash in 1989, then zsh — each replaceable because none of them is part of the system.
-
The prompt, the pipe and the redirect all date from the 1970s, and you will type them unchanged this week.
-
The name is literal. It is the shell around the kernel — the outer layer users touch, wrapping the core they must not. Whoever coined it was describing an architecture, not choosing a metaphor.
What it is — and what it is not
-
The outer frame is the terminal emulator — the window you see, click and resize.
-
Inside it runs the shell, the program reading your lines.
-
Beneath the shell sits the operating system, which actually starts programs and opens files — everything from last week.
It is not:
-
Not magical or privileged. The shell is one more user-space program, notable only for its job of launching others.
-
Not the same as the terminal. You can run a different shell in the same window, or the same shell over a network connection with no window at all.
-
Not a programming language you must learn first. It is a way to run programs; the language part comes later this week.
Why it was created and what problems it solves
-
Repetition. A graphical action happens once. A command can run a thousand times, tonight, without you.
-
Precision. “The third file from the top” is ambiguous. A path is not.
-
Composition. Small programs that each do one thing can be chained; windows cannot be chained.
-
Remoteness. Text travels down a slow connection. A desktop does not.
-
Reproducibility. You can paste a command into a bug report, a script or a Dockerfile. You cannot paste a sequence of clicks.
How it works
The read-eval-print loop
Typing ls -l /Users and pressing Return does exactly five things:
-
Prompt and read. The shell prints its prompt and waits. You type; the emulator shows the characters; nothing has run yet. Return hands over the line.
-
Parse and expand. The shell splits the line at spaces into
ls,-land/Users, and performs any expansions — turning a*into matching filenames, for instance. -
Locate and launch. It searches PATH for a program named
ls, asks the kernel to start it with those arguments, and waits. -
Print. The program writes its listing, which flows back through the shell to the emulator.
-
Loop. The program exits and a fresh prompt appears.
-
This loop is the shell’s heartbeat, exactly as fetch-decode-execute was the processor’s.
-
Everything else you will learn — pipes, variables, scripts — is a richer thing to do inside step 2. The loop never changes.
Finding the program
-
command not foundusually means “not on PATH”, not “not installed”. This is the single most common beginner confusion, and it has an easy check. -
type lstells you what a name actually is: a built-in, an alias, or a real program, and where it lives. -
echo $PATHshows the search list, colon-separated, in the order it is searched.
Expansion: what happens before the program runs
-
The program never sees what you typed. It sees what the shell made of it.
-
ls *.csvdoes not pass a star tols. The shell replaces the star with the matching filenames first, andlsreceives a list. -
If nothing matches, the star is passed through literally, which produces the confusing “no such file or directory: *.csv”.
-
Quoting switches expansion off.
"*.csv"reaches the program intact, which some programs —find,rsync— actually want. -
Learn this once and a whole class of mystery disappears: why a command behaves differently in a different directory, and why quoting a path with spaces is not optional.
An everyday analogy
A shop with a counter and a clerk.
| The shop | The terminal |
|---|---|
| The counter and window | The terminal emulator |
| The clerk | The shell |
| The stockroom and staff | The operating system |
| A written slip | A command line |
| ”Ready” on the sign | The prompt |
| The logbook of slips | Command history |
| Reference binders | man pages |
-
You hand over a slip; the clerk fetches. You do not go into the stockroom yourself — you are not allowed, and you do not need to be.
-
The clerk finishes your sentence when you start writing a long product name. That is tab completion.
-
The clerk does exactly what the slip says. Including, if that is what you wrote, throwing away the stock.
Examples in practice
-
ls -la ~/Downloads— one command, one flag bundle, one argument. You can now read every part of it. -
python3 train.py --epochs 10— identical structure. The program happens to be yours. -
command not found: pyton— a typo, caught by the PATH search. Tab completion would have prevented it. -
Permission denied— the kernel’s check from Day 6, surfacing at your prompt. -
man curlfollowed by/timeout— searching a manual page rather than searching the web.
Implications: security, privacy, performance, scalability, and cost
-
Security:
rmhas no recycle bin. The file is gone, immediately, with no confirmation. Runlson the target first — a habit that costs a second and has saved careers. -
Never pipe a download straight into a shell.
curl some-url | shruns code you have not read, with your privileges. Download, read, then run. -
Privacy:
psshows command-line arguments to every user. A key passed as an argument is not a secret. -
Performance: the shell itself is never your bottleneck. It launches programs; the programs do the work.
-
Cost: the terminal is how you avoid paying twice. A command that is written down runs identically next month, at 3am, without you awake to supervise it.
Alternatives: free, open source, and commercial
| Tool | Type | Why you might use it |
|---|---|---|
| Terminal.app / GNOME Terminal | Bundled, free | Already installed; entirely sufficient |
| iTerm2 (macOS) | Free | Split panes, better search, session history |
| Windows Terminal | Free | The good Windows option; use it with WSL2 |
| Warp, Ghostty | Free | Modern rendering, block-based output |
| VS Code integrated terminal | Free | The terminal beside your editor |
| tmux | Free, open source | Sessions that survive disconnection |
- Do not shop for a terminal yet. The bundled one teaches you everything this week covers. Change it when you know what annoys you.
Comparison with related concepts
| Term | What it actually is |
|---|---|
| Terminal | The window: draws text, accepts keystrokes |
| Terminal emulator | The same thing, named for the teletype it imitates |
| Shell | The program inside that interprets your lines |
| Console | Historically the machine’s own attached screen |
| Command line | The single line of text you typed |
| CLI | Any program driven by typed arguments, not just the shell |
When to use it — and when not to
-
Use the shell when the work repeats, when it must be exact, or when it happens on a machine with no screen.
-
Use it when you need to describe what you did to a colleague, a script or a bug report.
-
Use the graphical tool for genuinely visual work. Comparing images, arranging a layout, reading a long document — a window is better and nobody gains points for suffering.
-
Do not memorise commands. Learn to read them, and look up the rest.
manand--helpare the skill; recall is not.
The AI connection
-
Every framework installs from a command.
pip install torchis your first, and there will be thousands more. -
nvidia-smiis a terminal program, and it is how you find out whether your GPU is visible, busy, or too hot. -
Training runs are launched, monitored and killed from a shell — with the background jobs and signals you met yesterday.
-
Remote GPU machines have no desktop at all. You will connect over SSH into exactly this prompt.
-
Model configuration is command-line arguments. The structure you learned today is the structure of every experiment you will ever run.
Knowledge check
quiz:
question: "You install a tool, and running its name gives \"command not found\" — yet the file clearly exists on disk. What is the most likely explanation?"
options:
- "The directory containing it is not listed in PATH, so the shell never searches there"
- "The tool was installed for a different user account"
- "The shell needs to be restarted before any new program can be run"
- "The file was installed without read permission for your user"
answer_index: 0
explanation: "The shell searches only the directories named in PATH, in order. A program outside all of them is invisible to a bare name, though it will run perfectly if you give its full path."
Hands-on exercise
Read the loop, then use it. Worked through fully in the Day 8 lab directory.
| What you are doing | Command |
|---|---|
| See which shell you are in | echo $SHELL |
| See where it searches | echo $PATH |
| Ask what a name really is | type ls and type cd |
| Read a manual page | man ls (press q to quit) |
| Recall and edit a command | Up arrow, then Return |
| Complete a long name | Type a few letters, press Tab |
Expected output
/bin/zsh
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
ls is /bin/ls
cd is a shell builtin
lsis a file on disk, found by searching PATH.cdis a built-in — no file exists, because changing directory must happen inside the shell itself.
Validate your work
- You can name your shell and list the directories it searches
- You used
typeto distinguish a built-in from a program on disk - You opened a manual page and left it without closing the terminal
- You recalled a previous command and ran an edited version of it
- You completed a filename with Tab rather than typing it
-
bash tests/run_tests.shreports 0 failures
Troubleshooting
-
manopens and you are stuck. Pressq. Arrow keys scroll;/wordsearches. -
Tab does nothing. There is nothing unambiguous to complete. Press it twice to see the candidates.
-
$SHELLdisagrees with what you are using.$SHELLis your login shell; you may have started another one inside it. -
A command works for a colleague and not for you. Compare
echo $PATHbefore assuming anything is broken.
Common mistakes
-
Typing long paths by hand. Tab exists specifically to stop you.
-
Pasting commands without reading them, especially from a web page.
-
Reaching for
sudowhen something fails. Find out why first; the answer is usually PATH or a typo, andsudofixes neither. -
Treating “command not found” as “not installed”.
Practice assignment
-
Run ten commands you have never run before, taken from
manpages you open yourself. Record what each one does in your own words. -
Find three built-ins and three programs using
type, and explain why each one has to be what it is. -
Break PATH deliberately in a throwaway shell (
PATH=/bin), observe what stops working, then close the window to restore it. -
Reconstruct a command from history rather than retyping it, five times in a row, until the Up arrow is a reflex.
Extension challenge
-
Read your shell’s startup file (
~/.zshrcor~/.bashrc). You are not expected to understand every line; find the ones that set PATH. -
Write your own prompt. Change
PS1(bash) orPROMPT(zsh) to include the current directory and the last exit code. Getting the exit code into the prompt teaches you more than any tutorial. -
Time the difference. Rename fifty files by hand in a file browser, then do the same fifty with one command. Record both durations. That ratio is why this week exists.
Quiz
Q1. Which component actually reads your typed command, interprets it, and launches the right program?
- The terminal emulator
- The keyboard driver
- The operating system kernel by itself
- The shell
Show answer
Answer: D. The shell
The terminal emulator only displays text and forwards your keystrokes; the shell is the program running inside it that parses each command line and launches the program that does the work.
Q2. In the command `ls -l /Users`, what is `-l`?
- An option that changes how the command behaves
- An argument naming the folder to act on
- The name of the command being run first
- The shell's prompt string shown before it
Show answer
Answer: A. An option that changes how the command behaves
`ls` is the command and `/Users` is the argument it acts on; `-l` is an option, or flag, that switches `ls` into its long, detailed listing format.
Q3. What does the acronym REPL stand for, describing the shell's core behaviour?
- Run-Execute-Process-Log
- Read-Eval-Print Loop
- Receive-Encode-Parse-Launch
- Render-Emit-Print-List
Show answer
Answer: B. Read-Eval-Print Loop
A shell is a read-eval-print loop: it reads a line you type, evaluates it (parsing and finding the program), prints the result, and loops back to the prompt to wait for the next command.
Q4. Why does macOS show a `%` prompt by default while many Linux systems show `$`?
- macOS uses a graphical shell and Linux uses a text shell
- The `%` means an error occurred and `$` means success
- macOS defaults to zsh (`%`); many Linux systems default to bash (`$`)
- The symbol is chosen at random each time a new terminal window is opened
Show answer
Answer: C. macOS defaults to zsh (`%`); many Linux systems default to bash (`$`)
The prompt symbol comes from the default shell: zsh, the macOS default since Catalina in 2019, traditionally uses `%`, whereas bash, a common Linux default, traditionally uses `$`.
Q5. Which statement about most commands (like `ls` or `date`) is true?
- They only work when connected to the internet
- They are features built directly into the shell program itself
- They are part of the terminal emulator window
- They are separate programs on disk that the shell launches
Show answer
Answer: D. They are separate programs on disk that the shell launches
Most commands are independent programs the shell finds by searching the PATH and then runs; the shell's job is to locate the right program and pass along your options and arguments, not to do the work itself.
Q6. What is the purpose of tab completion?
- It completes a partly typed command or filename
- It opens the manual page for a command
- It deletes the current line entirely
- It runs the previous command again
Show answer
Answer: A. It completes a partly typed command or filename
Pressing Tab asks the shell to finish a partly typed command or filename (or show the choices if several match), which saves keystrokes and prevents typos in long names.
Q7. Which command shows the reference manual for a command such as `ls`?
- `help ls`
- `man ls`
- `info -q ls`
- `ls --manual`
Show answer
Answer: B. `man ls`
`man ls` opens the manual page for `ls`; you scroll with the arrow keys and press `q` to quit. Many commands also accept `--help` for a shorter summary.
Q8. You typed `bash` to start a new shell, but `echo $SHELL` still prints `/bin/zsh`. Why?
- The command failed silently and no shell is running
- `$SHELL` is always wrong and should be ignored
- `$SHELL` reports your login shell, not the running one
- zsh and bash are the same program with two names
Show answer
Answer: C. `$SHELL` reports your login shell, not the running one
`$SHELL` names your default login shell, which stays zsh even after you start bash by hand. To see the shell running at this moment, use `echo $0` or `ps -p $$`.
Glossary
- terminal
- The text-based interface for typing commands to a computer and reading their text output; historically a separate device at the end of a wire, today usually a software window.
- terminal emulator
- The application that opens a window, displays text, and forwards your keystrokes to the shell — a program that behaves like the old physical terminal hardware it is named after.
- shell
- The program running inside a terminal that reads your command lines, interprets them, launches the corresponding programs, and prints their output; examples include bash, zsh, and fish.
- prompt
- The short piece of text a shell prints to signal it is ready for your input, such as `you@laptop %`; its exact look is set by the prompt string.
- command
- A single line of text you give the shell, beginning with the name of a program to run and followed by any options and arguments.
- flag
- An option on a command line, usually starting with `-` or `--`, that changes how a command behaves — for example `-l` in `ls -l`.
- argument
- The target a command acts on, such as a file or folder name — for example `/Users` in `ls -l /Users`.
- bash
- The Bourne Again Shell, written by Brian Fox for the Free Software Foundation in 1989; the most widely documented shell and a common default on Linux systems.
- zsh
- The Z shell, released by Paul Falstad in 1990; the default shell on macOS since Catalina (2019), offering richer completion and customization while staying broadly bash-compatible.
- read-eval-print loop (REPL)
- The repeating cycle a shell runs for every command: read the line you type, evaluate it, print the result, and loop back to the prompt to wait for the next line.
- man page
- A command's built-in reference manual, shown by the `man` command (for example `man ls`); you scroll with the arrow keys and press `q` to quit.
- tab completion
- A shell feature that finishes a partly typed command or filename when you press the Tab key, or lists the choices if several match, saving keystrokes and preventing typos.
- command history
- The shell's record of the commands you have run, recalled with the Up arrow or listed with the `history` command, so past commands can be re-run without retyping.
- PATH
- The list of directories a shell searches to find the program named by a command, so that typing `ls` locates and runs the `ls` program wherever it is installed.
Sources and further reading
- The Missing Semester of Your CS Education — The Shell — MIT (accessed 2026-07-12) — Practical lecture and notes introducing the shell — the ideal companion to this lesson.
- The Linux Command Line — William Shotts (accessed 2026-07-12) — A gentle, thorough book taking readers from first commands through shell scripting; free to read online.
- Bash Reference Manual — GNU (accessed 2026-07-12) — The authoritative reference for bash, including its command syntax and features.
- Command-line interface — Wikipedia (accessed 2026-07-12)
- Unix shell — Wikipedia (accessed 2026-07-12)
Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.