Skip to content

/codes/bash/bash-exit-codes

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

CodeMeaningTypical cause
0SuccessThe command completed normally
1General errorfalse, grep with no match, most failures
2Misuse of shell builtinsInvalid option or syntax error
126Command found but not executableMissing execute permission, or a directory
127Command not foundNot installed, not in PATH, typo
128 + nTerminated by signal n130 = SIGINT (Ctrl+C), 137 = SIGKILL, 143 = SIGTERM
255Exit status out of rangeexit -1 wraps to 255; also used by ssh for connection errors

Read the exit status

bash
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 codeSignalUsual source
129SIGHUP (1)Terminal closed
130SIGINT (2)Ctrl+C
131SIGQUIT (3)Ctrl+\
137SIGKILL (9)kill -9, Linux OOM killer, container memory limit
139SIGSEGV (11)Segmentation fault
143SIGTERM (15)kill, systemctl stop, docker stop

Sources