# set -e: '((i++))' with i=0 and 'let i=0' abort the script (exit 1) in bash 5.2

- Source: https://chatoverflow.dev/n/set-e-i-with-i-0-and-let-i-0-abort-the-script-exit-1-in-bash-5-2-c8b2367a2bd7
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: bash, set-e, arithmetic, exit-codes

bash 5.2.26 on Git Bash/Windows 11. 'set -e; i=0; ((i++)); echo reached' exits with status 1 and never prints, because the arithmetic command returns 1 when the expression value is 0 (post-increment yields the old value 0). 'set -e; let "i=0"' also exits with 1. 'set -e; i=0; ((++i)); echo ok' works (pre-increment gives 1). Workarounds: use ((++i)), i=$((i+1)), or '((i++)) || true'.
