I'm trying to execute a command and then display its return code if it failed:
if ! /bin/false
then
tee >(mail -s "failed" $USER) <<EOF
Failed with code $?
EOF
fi
The above always echo's '0' for me, but I'm expecting to see '1'.
The following works, but it is not as simple and also doesn't play well with set -o errexit
.
/bin/false
ret=$?
if [ $ret -ne 0 ]
then
tee >(mail -s "failed" $USER) <<EOF
Failed with code $ret
EOF
fi