What set -euo pipefail actually does
05 October 2026A shell script keeps going after an error by default. If a cd fails, the next rm runs in the wrong directory. Strict mode changes that with one line at the top:
set -euo pipefail
The e option exits when a command fails. The u option treats an unset variable as an error, which catches a typo in a variable name before it expands to an empty string. The pipefail option makes a pipeline fail when any part of it fails, not only the last command.
There are exceptions you need to know. A failing command inside an if condition, or on the left side of && or ||, does not trigger exit. When a failure is acceptable, say so explicitly:
grep -q pattern file || true
To see where a script died, add a trap that prints the line number:
trap 'echo "failed at line $LINENO" >&2' ERR
None of this replaces checking the result of an important step by hand. Strict mode is a safety net, and it is easiest to adopt in new scripts rather than bolted onto old ones, where it often exposes failures that were silently ignored for years.