Floating-point exception (SIGFPE)
Production Risk
In bash, division by zero exits with 1 not 136; 136 appears when a child process receives SIGFPE.
Exit code 136 (128+8) indicates SIGFPE — a floating-point exception. Despite the name, this also covers integer division by zero, which is the most common cause in shell scripting contexts.
- 1Integer division by zero in a C program called from the script
- 2Arithmetic expression $(( n / 0 )) in bash itself
- 3Floating-point overflow or invalid operation in a compiled program
Bash arithmetic division by zero.
#!/bin/bash echo $(( 10 / 0 )) echo "Exit: $?"
expected output
bash: 10 / 0: division by zero (error token is "0") Exit: 1
Fix
Guard against zero divisors
WHEN Performing division in scripts
divisor=$1 if [ "$divisor" -eq 0 ]; then echo "Error: divisor cannot be zero" >&2 exit 1 fi result=$(( 100 / divisor ))
Why this works
Always validate divisors before performing division; division by zero is undefined.
✕ Use bc or awk without checking the divisor
bc and awk also error on division by zero, though they may produce different exit codes.
GNU Bash Manual — Signals
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev