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/log

After 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 main

git 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.txt

The 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
Answer: app.log
2. Why can two commands give -r different meanings?
Answer: The shell passes -r as an argument; each command defines how it interprets that argument.

Keep building

Authoritative references

Make the idea retrievable.

Study this concept with spaced repetition, next to the commands where you use it.

Get Terminaster