# Guided Exercise: Predict the Exit Code Before You Run It This is a paper exercise — commit to an answer before checking it in the Lab. ## Your task For each command below, predict whether its exit code will be `0` (success) or non-zero (failure), and why: 1. `cat /etc/hostname` (a file that exists) 2. `cat /etc/does-not-exist-at-all` (a file that doesn't) 3. `grep root /etc/passwd` (a pattern that's very likely present) 4. `grep zzz-not-a-real-user /etc/passwd` (a pattern that's very likely absent) 5. `mkdir /tmp/already-exists && mkdir /tmp/already-exists` (running the same `mkdir` twice) ## A worked shape to check yourself against 1. `0` — the file exists and is readable. 2. Non-zero — the file doesn't exist, `cat` fails. 3. `0` — `grep` succeeds (exit 0) when it finds at least one match. 4. Non-zero (specifically `1`) — `grep` "fails" when it finds NO matches, even though nothing went technically wrong. This is a common surprise: `grep`'s exit code means "did I find a match," not "did an error occur." 5. The SECOND `mkdir` fails (non-zero) — the directory already exists. The first one succeeds. ## Instructor Notes **Facilitation:** Item 4 is the one worth pausing on — many students assume "no error message" means "exit code 0," and `grep`'s no-match convention is a good early counter-example. **Approximate timing:** 8-10 minutes live discussion; 5 minutes self-paced.