In the function "handleExit" below, the exitCode is zero, ie, "0". i want it to be "1". My function called "exit 1". What do I need to do in order to detect that the function "writeToErr" had a non-zero status.
#!/bin/bash
set -euo pipefail
logError() {
awk " BEGIN { print \"$@\" > \"/dev/fd/2\" }"
}
function writeToErr () {
echo "standard out"
logError "standard err"
exit 1
}
function wrapper () {
writeToErr >>output.log 2>&1
}
function handleExit () {
echo "handle exit"
exitCode=$?
if [ $exitCode -eq "0" ]
then
echo "No problem"
else
echo "$0 exited unexpectedly with status:$exitCode"
exit 1
fi
}
trap wrapper EXIT
handleExit >>output.log 2>&1
And here are the contents of "output.log":
handle exit
No problem
standard out
standard err