Systems

exit code

An exit code is the single number a program hands back when it finishes — its way of saying 'this went fine' or 'something broke'. By a near-universal convention, 0 means success and anything else (1, 2, 127…) means some kind of failure. It's the program's last word before it leaves.

You rarely see it, because it's not printed — it's tucked away for the next program to read. In a shell you can peek at it with $? right after a command, or just chain commands together: 'build && deploy' only runs deploy if build exited 0, because && means 'and only if that succeeded'.

This quiet number is the whole reason automation works. When CI says your build 'failed', what really happened is a step finished with a non-zero exit code, and the pipeline noticed. Computers can't read your test output, but they can always read a 0.

$ grep "TODO" notes.txt
$ echo $?
1            # 1 = grep found nothing; 0 would mean it did

$? holds the last command's exit code — here, 'no match found'.

0 = success feels backwards at first — think of it as 'zero problems', not 'zero done'.

Also called
exit statusreturn codestatus codeerrorlevel$?