blob: f49ebf588911eb506e651c73b77374628c659e00 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001# Contributed by Noah Friedman and Roland McGrath.
2
3# To be run by the PROMPT_COMMAND variable, so that one can see what
4# the exit status of processes are.
5
6function check_exit_status ()
7{
8 local status="$?"
9 local signal=""
10
Jari Aaltob80f6442004-07-27 13:29:18 +000011 if [ ${status} -ne 0 ] && [ ${status} != 128 ]; then
Jari Aalto726f6381996-08-26 18:22:31 +000012 # If process exited by a signal, determine name of signal.
13 if [ ${status} -gt 128 ]; then
Jari Aaltoccc6cda1996-12-23 17:02:34 +000014 signal="$(builtin kill -l $((${status} - 128)) 2>/dev/null)"
Jari Aalto726f6381996-08-26 18:22:31 +000015 if [ "$signal" ]; then signal="($signal)"; fi
16 fi
17 echo "[Exit ${status} ${signal}]" 1>&2
18 fi
19 return 0
20}
21
22PROMPT_COMMAND=check_exit_status