whatis exit-code

Exit Code

Also known as: exit status, return code, $?

The number from 0 to 255 a program returns when it finishes. Zero means success; anything else signals an error.

What Is an Exit Code in Linux?

The shell stores the last command's exit status in $?. Constructs like if, &&, and || all test it, so mkdir dir && cd dir only changes directory if mkdir succeeded.

Some codes are conventional: 1 is a general error, 2 is misuse, 126 is "not executable", 127 is "command not found", and 128 plus N means the process was killed by signal N (so 137 is SIGKILL, often from the OOM killer).

Example

grep -q root /etc/passwd; echo $?
# 0