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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

set -e  set -u  set -o pipefail  set -x

Parameters

ParameterDescription
-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

-e and pipefail
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.

Tracing with -x
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.

Was this page helpful?