Exit Codes Explained: What 0, 1, and 137 Mean

Every command you run leaves behind a number, and scripts live or die by it. Zero means success, anything else means trouble — and a few specific codes tell you exactly what went wrong.

BytExplorer 5 min read July 1, 2026

Every command you run finishes by handing back a single number — its exit code — even when you never notice it. It's how a program tells whoever launched it whether things went fine. Humans read the printed output; scripts and pipelines read this number. Once you know how to check it, a lot of "why did my script stop?" becomes obvious.

What an exit code is

When a process ends, it returns an integer from 0 to 255 to its parent. You almost never see it, but the shell keeps the last one in a variable called $?:

ls /etc
echo $?        # 0  → the previous command succeeded

ls /nope
echo $?        # 2  → it failed

The only rule that always holds

0 means success. Anything non-zero means failure. That's the universal contract. The specific non-zero number is a hint about what kind of failure, but any non-zero at all means "this did not go well."

Don't overthink the number first — check whether it's zero. Zero is "OK, carry on"; non-zero is "stop, something's wrong." Scripts make every decision on exactly that distinction.

Codes worth recognising

A handful come up constantly:

  • 0 — success.
  • 1 — generic, catch-all error.
  • 2 — misuse of a command (bad argument or option).
  • 126 — found the command but it isn't executable (permissions).
  • 127 — command not found (typo, or not on your PATH).
  • 130 — you stopped it with Ctrl-C.
  • 137 — force-killed (often the out-of-memory killer): 128 + 9 for SIGKILL.

Why scripts and pipelines care

Automation chains commands on this number. && means "only continue if the last exit code was 0"; CI pipelines fail a build the moment any step returns non-zero:

npm test && npm run build      # build only runs if tests exit 0

That single convention is what lets a pipeline stop itself the instant something breaks.

The mental model to keep

Every command whispers a number on its way out: 0 for "fine," anything else for "not fine." You read it with $?, tools chain decisions off it with &&, and the odd specific codes (127, 137) are just labelled ways of failing. Check zero-vs-non-zero first; decode the exact number second.

Put it into practice

Stop reading, start building

This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.

More in Core Concepts