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.
More on Functions, exit codes, strict mode and traps
How do you define a function, pass arguments and return a value?BeginnerWhat does `local` do, and what is dynamic scoping?AdvancedWhy is `local out=$(cmd)` a problem under `set -e`?AdvancedWhat does `set -e` do, and where does it NOT cause an exit?AdvancedExplain `set -euo pipefail` line by line, and add the `-E` flag.BeginnerWhy can `((count++))` kill a script under `set -e`?Intermediate