A script with `set -e` stops silently right after `((retries++))` on its first pass. No error message, exit code 1.
IntermediateTroubleshootingTroubleshooting: strict mode, exit codes, pipelines and traps
Answer
Likely causes → (( expr )) returns status 1 when the expression evaluates to 0. Post-increment returns the old value, so ((retries++)) with retries=0 evaluates to 0, returns 1, and set -e exits. The same happens with ((count--)) reaching zero or (( x = 0 )).
Diagnose →
bash -c 'set -e; n=0; ((n++)); echo "never printed"'; echo "rc=$?" # rc=1
bash -x ./script.sh 2>&1 | tail -5 # last traced line is the (( ))
Fix → Use an assignment form, which always succeeds:
retries=$((retries + 1)) # or: (( ++retries )) (pre-increment, returns the new value)
(( retries++ )) || true # if you must keep the old form
Prevent → Ban bare ((x++)) in style guides; use x=$((x + 1)). A bats test that runs the loop's first iteration catches it.
More on Troubleshooting: strict mode, exit codes, pipelines and traps
`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.AdvancedYou added `trap 'echo "failed at line $LINENO" >&2' ERR`, but when a command inside a function fails, nothing is printed and the script just exits.Intermediate