Created
May 19, 2015 20:37
-
-
Save philpennock/1babd79316413579a343 to your computer and use it in GitHub Desktop.
Shell sucks; tried in bash, zsh, BSD sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
script_name="$(basename "$0")" | |
die() { | |
local rv=$? | |
printf >&2 "%s: %s\n" "$script_name" "$*" | |
exit $rv | |
} | |
will_fail_return() { | |
echo "in will_fail_return" | |
return 42 | |
} | |
( | |
set -e -u | |
set +o | |
will_fail_return | |
echo $? | |
echo "got to end of subshell" | |
) || die "subshell failed" | |
echo "reached end of entire script" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not that. It's because of the
|| die
at the end of the sub-shell, which changes how-e
is applied within the subshell. Without|| die
,-e
will cause an early exit. But with-e
not in effect within the subshell, this is ... horrible.So, need to do explicit die afterwards.
Oh fscking eww.