Exit status as seen on shell command line |
$?
.
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) | n | 0 | 0000000 | n |
signal m, with core dump | 00000000 | 1 | m | m+128 |
signal m, no core dump | 00000000 | 0 | m | m+128 |
stop/suspend signal m | m | 0 | 1111111 | - |
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