help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] access exit code from within exit trap handler?


From: Patrick Schleizer
Subject: [Help-bash] access exit code from within exit trap handler?
Date: Tue, 14 Apr 2015 11:19:09 +0000

Hi!

Code talks. I'll include my question within the following pseudo code.

#!/bin/bash
set -x
exit_handler() {
   ## Is there a way figure out what exit code caused execution of this
handler?
   true "exit code: "
   ## ...
}
trap exit_handler EXIT
true "something..."
if [ "something" = "something" ]; then
   exit 1
fi
## ...
exit 0

Sure, a simple function
exit_() {
   exit_code="$1"
   exit "$exit_code"
}
would probably do, but perhaps this can be avoided?

Cheers,
Patrick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]