18. Exit Status

A process terminates by calling exit system call along with a status from 0 to 255. Within the UNIX world 0 means successful termination. Any number greater 0 points to an irregular termination:

$ (exit 254)
$ echo "Last command exits by: $?"
Last command exits by: 254

The parameter $? keeps the exit status of the most recent executed foreground command. The exit status can be used to determine further procession. The execution of a sequence of commands separated by the "&&" (AND) operator breaks after the first command which does not terminate successfully:

$ echo a && echo b && (exit 1) && echo c
a
b

The execution of a sequence of commands separated by || (OR operator) breaks after the first command which terminates successfully:

$ (exit 1) || echo a || echo b
a