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

What are the conventional exit codes, and what do 126, 127, 130, 137 and 143 mean?

BeginnerConceptFunctions, exit codes, strict mode and traps
Answer
Code Meaning
0 success
1 general error
2 misuse of a builtin / bad usage
126 file found but not executable (Permission denied)
127 command not found
128+N killed by signal N
130 SIGINT (Ctrl+C)
137 SIGKILL (often the OOM killer or kill -9)
143 SIGTERM

Exit codes are taken modulo 256, so exit 256 is 0 and exit -1 is 255. Define your own codes (e.g. 3 = config error) in the usage text so callers can branch on them.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Functions, exit codes, strict mode and traps