Exit status as seen on shell command line
The exit status of a command can be seen using the shell's $?. It is convenient to have this as part of the shell prompt by adding ${?##0} to the value of the PS1 prompt variable.

The exit status is typically 16 bits as described in the pipe, fork and exec notes. The value $? the shell displays is an 8 bit integer in the range 0 - 255 as follows:

Status from:bits 15-8: bit 7:bits 6-0:$?:
exit(n)n00000000n
signal m, with core dump  00000000  1mm+128
signal m, no core dump000000000mm+128
stop/suspend signal mm01111111  -

Programs that use exit(-1) will have $? = 255.
If a non-existent program is run the return from exec is a -1, which the shell displays as $? = 128 - 1 = 127.
Sigint (^C) is signal 2, so $? is 128 + 2 = 130.
Sigquit (^/) is signal 3, so $? is 128 + 3 = 131.

Last update: 2001 January 15