Error codes & fixes: Exit codes
10 Error codes & fixes commands: Exit codes. Click a command to see what each part does.
Exit codes10
echo $?$?What did the last command return?What it means
Every command returns a number 0-255. 0 means success. CI jobs and
&&use it.Usual causes & fixes
- Check it right after the command; the next command overwrites it.
- In scripts use
set -eto stop on the first failure,set -o pipefailto catch failures inside pipes.
Diagnose: what each part of the command does
echoprint$?exit status of the last command: 0 = success, anything else = failure
bash -x <script>.sh1General error: trace the scriptWhat it means
Catch-all for general errors: the program failed and chose 1.
Usual causes & fixes
- Read the last lines of stderr: the real message is usually there.
- A command inside the script failed:
-xshows which one.
Diagnose: what each part of the command does
bashrun the script with bash-xprint every command (with expanded variables) before running it
<command> --help2Misuse / wrong argumentsWhat it means
Bash builtins return 2 for incorrect usage (invalid option, missing argument); many tools follow this.
Usual causes & fixes
- Typo in a flag or a missing required argument.
- Shell syntax error in a script.
Diagnose: what each part of the command does
--helpshow valid options and arguments
ls -l <file>; file <file>126Found but cannot executeWhat it means
The command exists but is not executable.
Usual causes & fixes
- Missing execute bit:
chmod +x <file>. - Windows line endings in a script:
sed -i 's/\r$//' <file>(or dos2unix). - Filesystem mounted
noexec:findmnt -o TARGET,OPTIONS -T <file>.
Diagnose: what each part of the command does
ls -l <file>check the x permission bitfile <file>check the type: script with CRLF line terminators, wrong binary format…
- Missing execute bit:
command -v <command> || echo "not found; PATH=$PATH"127Command not foundWhat it means
The shell could not find the program in any PATH folder.
Usual causes & fixes
- Not installed (install it with apt/dnf/apk).
- Installed in a folder not on PATH (e.g. ~/.local/bin):
export PATH="$HOME/.local/bin:$PATH". - Typo, or a container image that does not include the tool (distroless, alpine without bash).
Diagnose: what each part of the command does
command -v <command>print where the command is, or nothing if it is not found||if that failed…echo "…PATH=$PATH"…show the folders the shell searches
kill -l $(( <exit-code> - 128 ))128+NKilled by a signal: which one?What it means
When a process dies from signal N, the shell reports 128+N. E.g. 137 → 9 (KILL), 143 → 15 (TERM), 130 → 2 (INT).
Usual causes & fixes
- Run it with the code you got, e.g.
kill -l $(( 137 - 128 ))prints KILL.
Diagnose: what each part of the command does
kill -l <number>print the signal name for a number$(( … ))shell arithmetic<exit-code> - 128exit codes above 128 mean "terminated by signal N"
- Run it with the code you got, e.g.
kill -l 2130Stopped with Ctrl+CWhat it means
128 + 2 (SIGINT): someone (or something) pressed Ctrl+C / sent an interrupt.
Usual causes & fixes
- Expected if you stopped it. In CI it usually means the job was cancelled.
Diagnose: what each part of the command does
kill -l 2signal 2 = INT, what Ctrl+C sends
dmesg -T | grep -i -E "out of memory|killed process"137Killed (SIGKILL): usually out of memoryWhat it means
128 + 9 (SIGKILL): the process was force-killed. In containers this is almost always the memory limit (OOMKilled).
Usual causes & fixes
- Docker:
docker inspect --format '{{.State.OOMKilled}}' <container>; raise-mor fix the leak. - Kubernetes:
kubectl describe pod <pod>→ Last State: Terminated, Reason: OOMKilled; raiseresources.limits.memory. - A human or script ran
kill -9, or a stop timed out and was escalated.
Diagnose: what each part of the command does
dmesg -Tkernel messages with readable timestampsgrep -i -E "out of memory|killed process"the OOM killer lines
- Docker:
dmesg -T | grep -i segfault139Segmentation fault (SIGSEGV)What it means
128 + 11 (SIGSEGV): the program accessed invalid memory and crashed.
Usual causes & fixes
- Bug in a native binary or library; version mismatch between binary and libs (e.g. glibc vs musl/alpine).
- Wrong CPU architecture image under emulation.
Diagnose: what each part of the command does
dmesg -Tkernel loggrep -i segfaultlines about the crash (which binary, which library)
docker inspect --format '{{.State.ExitCode}} {{.State.FinishedAt}}' <container>143Terminated (SIGTERM): asked to stopWhat it means
128 + 15 (SIGTERM): a graceful stop request: docker stop, a Kubernetes rollout/scale-down, systemctl stop.
Usual causes & fixes
- Normal during deploys and restarts.
- If unexpected: check who stopped it (events,
kubectl get events, systemd journal). - App should handle SIGTERM and exit cleanly within the grace period (
terminationGracePeriodSeconds, default 30s).
Diagnose: what each part of the command does
docker inspectcontainer details--format '…'print just the exit code and when it stopped
Nothing matches.
My DevOps Playbook by Angelo John Calleja