An exit status is a number from 0 to 255 that a process gives back to its parent when it ends. 0 means success. Any other number means failure. &&, ||, set -e and CI pipelines all check this. In a shell, $? holds the status of the last command.
The common codes:
- 1 is the generic failure most programs use. Node uses it when it crashes on an uncaught exception.
- 126 means the shell found the command but couldn't run it. Often the file doesn't have execute permission.
- 127 means "command not found". For example, a typo, or a program that isn't in
PATH. - 128 + n means a signal number n killed the process. So 130 is SIGINT from Ctrl-C, 137 is SIGKILL and 143 is SIGTERM.
Only the lowest 8 bits are kept, so exit(256) is reported as 0.
- 0 means success and any other number means failure.
$?holds the last command's status. - 1 is a generic error.
- 126 means the file can't be executed, and 127 means command not found.
- 128 + n means signal n killed the process: 130 is SIGINT, 137 is SIGKILL, 143 is SIGTERM.
Read more