Interview Prep/Shell Scripting/Functions, exit codes, strict mode and traps

Why can `((count++))` kill a script under `set -e`?

IntermediateConceptFunctions, exit codes, strict mode and traps
Answer

(( expr )) returns 1 when the expression evaluates to 0. Post-increment returns the old value, so when count is 0, ((count++)) evaluates to 0, returns status 1, and set -e exits.

set -e
count=0
((count++))        # script exits here
((++count))        # fine (evaluates to 1)
count=$((count + 1))   # clearest and always safe
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Functions, exit codes, strict mode and traps