[Bash] Exit early after a command fails with set -e

Created on November 30, 2026

Enable set -e to make Bash exit when an ordinary command returns a nonzero status.

bash -c 'set -e; false; echo "This will not run"'
echo "$?"
1

false returns 1, so the child shell exits before running echo. set -e is the short form of set -o errexit. Bash makes exceptions for commands used in conditions, including some positions in if, &&, and ||.

Bash