Bash 5 reference · Shell Builtins and Syntax
set -euo pipefail (Bash builtin)
Turn on strict mode: exit on errors (-e), fail on unset variables (-u), and fail pipelines when any part fails.
Bash 5
Syntax
set -e set -u set -o pipefail set -x
Parameters
| Parameter | Description |
|---|---|
-e |
Exit when a command fails (not in conditions). |
-u |
Error on unset variables. |
-o pipefail |
A pipeline fails if any command fails. |
-x |
Print each command before running it (debugging). |
Examples
bash -c 'set -e; false; echo not printed' || echo "stopped with $?"
bash -c 'set -o pipefail; false | true' || echo "pipefail caught it ($?)"
Output
stopped with 1 pipefail caught it (1)
Run this on your computer — see “Get Started” for setup.
bash -c 'set -x; n=3; echo $((n * 2))' 2>&1
Output
+ n=3 + echo 6 6
Run this on your computer — see “Get Started” for setup.
Related
trap· Run commands when the script exits or receives a signal; the standard way to clean up temporary files and child processes.- Bash Error Handling: set -euo pipefail and trap · tutorial