summaryrefslogtreecommitdiff
path: root/examples/functions/exitstat
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2007-11-12 13:06:02 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2007-11-12 13:06:02 -0800
commitb7fc9e0f6d6105ba2203f219743d4b269415e84b (patch)
treeef6586dfc62798c2b17487b443864699aca55f31 /examples/functions/exitstat
downloadvyatta-bash-b7fc9e0f6d6105ba2203f219743d4b269415e84b.tar.gz
vyatta-bash-b7fc9e0f6d6105ba2203f219743d4b269415e84b.zip
initial import from bash_3.1dfsg.orig.tar.gz
Diffstat (limited to 'examples/functions/exitstat')
-rw-r--r--examples/functions/exitstat22
1 files changed, 22 insertions, 0 deletions
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