退出码的有效范围是 0~255。0 代表正常,其他都是异常。
如果程序内设置的退出码超过 255,比如 exit 3809
则退出码是 225,因为会取模计算 3809 % 256 = 225
。
如果程序内设置的退出码返回负数,比如 exit -1
,则退出码是 255。
退出码的取值有特别含义,
1
- Catchall for general errors2
- Misuse of shell builtins (according to Bash documentation)126
- Command invoked cannot execute127
- command not found128
- Invalid argument to exit128+n
- Fatal error signal “n”130
- Script terminated by Control-C255
- Exit status out of range