Table D-1. Reserved Exit Codes
| Exit Code Number | Meaning | Example | Comments |
|---|---|---|---|
| Catchall for general errors | let "var1 = 1/0" | Miscellaneous errors, such as "divide by zero" and other impermissible operations | |
| Misuse of shell builtins (according to Bash documentation) | Seldom seen, usually defaults to exit code 1 | ||
| Command invoked cannot execute | Permission problem or command is not an executable | ||
| "command not found" | Possible problem with | ||
| Invalid argument to exit | exit 3.14159 | exit takes only integer args in the range 0 - 255 (see first footnote) | |
| Fatal error signal "n" | kill -9 | ||
| Script terminated by Control-C | Control-C is fatal error signal 2, (130 = 128 + 2, see above) | ||
| Exit status out of range | exit -1 | exit takes only integer args in the range 0 - 255 |
According to the above table, exit codes 1 - 2, 126 - 165, and 255 [1] have special meanings, and should therefore be avoided for user-specified exit parameters. Ending a script with exit 127 would certainly cause confusion when troubleshooting (is the error code a "command not found" or a user-defined one?). However, many scripts use an exit 1 as a general bailout-upon-error. Since exit code 1 signifies so many possible errors, it is not particularly useful in debugging.
There has been an attempt to systematize exit status numbers
(see
![]() | Issuing a $? from the command line after a shell script exits gives results consistent with the table above only from the Bash or sh prompt. Running the C-shell or tcsh may give different values in some cases. |
| [1] | Out of range exit values can result in unexpected exit codes. An exit value greater than 255 returns an exit code modulo 256. For example, exit 3809 gives an exit code of 225 (3809 % 256 = 225). |
| [2] | An update of |