Terminal · foundation
Command anatomy
A shell command is a sequence of words that identifies a command to run and supplies its options, option values, and positional arguments according to that command's interface.
Why it matters
Correctly separating shell syntax from a program's own arguments makes unfamiliar commands easier to read, debug, and verify before execution.
Mental model
How to reason about command anatomy
The shell first parses and expands its own syntax, then passes an ordered argument vector to the selected program; the program decides what those resulting arguments mean.
Analogy
Think of the shell as a dispatcher that prepares an addressed envelope: it chooses the recipient program and delivers an ordered list of words, while the recipient interprets the contents.
Examples
See the boundary, not just the happy path
Worked example · Inspect a directory
ls -la /var/logAfter shell parsing, ls receives two arguments: -la, which ls interprets as combined options, and /var/log, which it interprets as the target path.
Worked example · Option with a value
git log --max-count=5 --oneline maingit selects its log subcommand; log then interprets two options and the positional revision main. The equals form binds 5 to its option unambiguously.
Useful contrast · Shell operator, not an argument
printf '%s\n' hello > output.txtThe unquoted > is consumed by the shell as redirection, so printf does not receive > or output.txt in its argument vector.
Common mistakes
Misconceptions to remove early
Assuming every dash-prefixed word has universal meaning
Options belong to each command's interface; -r can mean recursive, reverse, or something else, so consult that command's documentation.
Forgetting the end-of-options marker
A filename such as -draft may be mistaken for an option; commands following the common convention accept -- to mark all remaining words as positional arguments.
Quick check
Can you predict the result?
1. In grep -n error app.log, which word is the positional file argument?
- • app.log
- • -n
- • error
2. Why can two commands give -r different meanings?
Keep building