Shell
Core Idea
A shell is a command interpreter. It reads a line of text, expands shell syntax, starts programs, connects streams, and reports success or failure. Bash is the shell used for this course.
Command Anatomy
grep -R makers ~/src/pages > ~/playground/matches.txt 2>/dev/null
grepis the command name.-Ris an option.makersand~/src/pagesare arguments.>redirects stdout.2>redirects stderr.- The shell expands
~beforegrepstarts.
What The Shell Does Before A Program Runs
- Reads your line.
- Splits it into words using shell rules.
- Expands variables such as
$USER. - Expands
~and some patterns. - Sets up pipes and redirection.
- Starts the command.
- Stores the exit status in
$?.
Why Quoting Matters
name='Ada Lovelace'
printf '%s\n' $name
printf '%s\n' "$name"
Unquoted variables can split into multiple words. Quoted variables preserve one value. This is why scripts in the course use "$1", "$HOME", and "$name".
Interactive Shell Versus Script
An interactive shell prints a prompt and waits for you. A script is a file of shell commands run by a shell. The same syntax appears in both, but scripts need more discipline: shebang, set -euo pipefail, argument checks, and predictable output.
Common Confusions
- The shell expands
$HOME;lsreceives the expanded path. cdis a shell builtin because it changes the shell’s own current directory.man cdmay not help because some commands are shell builtins; usehelp cdin Bash.- A command’s output is not the same as its exit status.
sudois not a shell feature and is not part of ordinary learner work on the shared server.
Proof Check
Run type cd, type grep, and type printf. Explain which are shell builtins and which are external commands on this system.
Docs Pointers
- Run
man bash, then readSHELL GRAMMAR,QUOTING,REDIRECTION, andPipelines. - Run
help,help cd,help type, andhelp set. - Read the Bash Reference Manual.
- Read Terminal to separate the shell from the terminal app.
- Read Readline for Bash prompt movement, editing, completion, and history search keystrokes.
- Read I/O, File Descriptor, and Signal to understand streams, redirection, and interrupts.

Linux Foundations