Bash exit codes: 0, 1, 2, 126, 127, 128+n and 255
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
- tool
- Bash
- versions
- bash 4.x, bash 5.x
- os
- linux, macos, windows
Every command returns an exit status from 0 to 255; $? holds the status of the last command. 0 means success and any other value means failure. bash reserves a few values: 126 (found but not executable), 127 (command not found) and 128 + n (terminated by signal n).
Exit code table
| Code | Meaning | Typical cause |
|---|---|---|
| 0 | Success | The command completed normally |
| 1 | General error | false, grep with no match, most failures |
| 2 | Misuse of shell builtins | Invalid option or syntax error |
| 126 | Command found but not executable | Missing execute permission, or a directory |
| 127 | Command not found | Not installed, not in PATH, typo |
| 128 + n | Terminated by signal n | 130 = SIGINT (Ctrl+C), 137 = SIGKILL, 143 = SIGTERM |
| 255 | Exit status out of range | exit -1 wraps to 255; also used by ssh for connection errors |
Read the exit status
true; echo "true -> $?"
false; echo "false -> $?"
grep -q needle <<< "haystack"; echo "grep without match -> $?"
nonexistent-tool 2>/dev/null; echo "not found -> $?"
(exit 300); echo "exit 300 -> $?"Output
true -> 0 false -> 1 grep without match -> 1 not found -> 127 exit 300 -> 44
Values above 255 wrap modulo 256, so exit 300 returns 44.
Signals: 128 + n
When a process is killed by a signal, bash reports 128 plus the signal number. Common values on Linux:
| Exit code | Signal | Usual source |
|---|---|---|
| 129 | SIGHUP (1) | Terminal closed |
| 130 | SIGINT (2) | Ctrl+C |
| 131 | SIGQUIT (3) | Ctrl+\ |
| 137 | SIGKILL (9) | kill -9, Linux OOM killer, container memory limit |
| 139 | SIGSEGV (11) | Segmentation fault |
| 143 | SIGTERM (15) | kill, systemctl stop, docker stop |
Sources
Related pages
errors · bashbash: command not found (exit status 127)bash prints "command not found" and exits with status 127 when a command is not in PATH, not installed or misspelled. Check with command -v and fix PATH.flags · bashset -euo pipefail: what each flag does in bashset -e exits on the first failing command, -u treats unset variables as errors and -o pipefail makes a pipeline fail if any command in it fails. Examples.cheat sheets · bashBash cheat sheet: variables, tests, loops and expansionsBash cheat sheet with the syntax you use daily: variables, parameter expansion, tests, loops, functions, arrays, redirection and safe script headers on a page.