File: exitstat

package info (click to toggle)
bash 5.1-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,116 kB
  • sloc: ansic: 112,107; sh: 7,438; yacc: 5,518; makefile: 4,533; perl: 4,227; asm: 48; awk: 23; sed: 16
file content (22 lines) | stat: -rw-r--r-- 620 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Contributed by Noah Friedman and Roland McGrath.

# To be run by the PROMPT_COMMAND variable, so that one can see what
# the exit status of processes are.

function check_exit_status ()
{
 local status="$?"
 local signal=""

    if [ ${status} -ne 0 ] && [ ${status} != 128 ]; then
       # If process exited by a signal, determine name of signal.
       if [ ${status} -gt 128 ]; then
          signal="$(builtin kill -l $((${status} - 128)) 2>/dev/null)"
	  if [ "$signal" ]; then signal="($signal)"; fi
       fi
       echo "[Exit ${status} ${signal}]" 1>&2
    fi
    return 0
}

PROMPT_COMMAND=check_exit_status