`result=$(compute_checksums; echo done)` returns `done` even when `compute_checksums` fails, despite `set -e`.
AdvancedTroubleshootingTroubleshooting: strict mode, exit codes, pipelines and traps
Answer
Likely causes → Command substitutions run in a subshell, and Bash clears errexit inside them by default (outside POSIX mode). The failure inside is ignored, the last command (echo) succeeds, and the substitution's status is 0.
Diagnose →
bash -c 'set -e; x=$(false; echo ok); echo "x=$x"' # x=ok
bash -c 'set -e; shopt -s inherit_errexit; x=$(false; echo ok); echo "x=$x"' # exits 1
Fix → Turn on inherit_errexit (Bash 4.4+) next to the strict header, and keep one command per substitution:
set -Eeuo pipefail
shopt -s inherit_errexit
sums=$(compute_checksums) # status of compute_checksums propagates to the assignment
Prevent → Avoid multi-command substitutions; if a substitution must do several things, make it a function that returns its own errors explicitly.
More on Troubleshooting: strict mode, exit codes, pipelines and traps
A script with `set -e` stops silently right after `((retries++))` on its first pass. No error message, exit code 1.Intermediate`notify.sh: line 9: SLACK_WEBHOOK: unbound variable` — but the webhook is meant to be optional.BeginnerOn a CentOS 7 / Amazon Linux 2 host, `deploy.sh "${extra_args[@]}"` fails with `extra_args[@]: unbound variable`. It works on your laptop.Advanced`local release=$(curl -fsS "$API/latest")` fails with a 503, yet the function happily continues and deploys an empty release name.IntermediateA check `procs=$(ps aux | grep -v grep | grep -c '[n]ginx: worker')` kills the script under `set -euo pipefail` whenever nginx is down, before the alert code runs.IntermediateA script that does `first=$(sort -u huge.txt | head -n 1)` exits with status 141 under `pipefail`, but only on large inputs.Advanced