# Demonstration: Watching Exit Codes in Real Time ## OBSERVE Run a command you know will succeed, then immediately check its exit code: ``` $ true $ echo $? 0 ``` ## HYPOTHESIS Now predict: what will the exit code be if the command fails instead? ## INSPECT Run a command that fails, and check immediately: ``` $ ls /this-does-not-exist ls: cannot access '/this-does-not-exist': No such file or directory $ echo $? 2 ``` ## CHANGE Try a few other failing commands and note their codes: `grep nomatch /etc/hostname` (exit 1 — "no matches found," a different kind of failure than "file not found"). ## VERIFY Notice: exit codes aren't just "0 or 1" — different failures often get different non-zero codes. `0` always means success; the exact non-zero value's MEANING varies by command, but ANY non-zero value reliably means "something went wrong," which is the part every script actually relies on (`if command; then ... else ...`). ## Instructor Notes **Demo goal:** Make the abstract "exit code" concept concrete by actually watching `$?` change in real time, immediately after each command — this is far more convincing live than described in prose. **Approximate timing:** 8 minutes live. **Common mistake to watch for:** running `echo $?` after ANY other command in between (even `ls`) silently checks the WRONG command's exit code — emphasize "check it immediately."