From 1d5cace9db9aef76f26b2d7ba54bbb76443b00b2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 20:33:23 +0200 Subject: Adding upstream version 5.0. Signed-off-by: Daniel Baumann --- examples/functions/exitstat | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/functions/exitstat (limited to 'examples/functions/exitstat') diff --git a/examples/functions/exitstat b/examples/functions/exitstat new file mode 100644 index 0000000..f49ebf5 --- /dev/null +++ b/examples/functions/exitstat @@ -0,0 +1,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 -- cgit v1.2.3