Created
February 11, 2018 01:44
-
-
Save dreness/e9d4a93957962209706fe5c44218e56d to your computer and use it in GitHub Desktop.
a few bash techniques for error handling
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
#!/usr/bin/bash | |
trap "echo inner ERR" ERR | |
trap "echo inner EXIT" EXIT | |
aThunk() | |
{ | |
unsurprisingly | |
} | |
doIts() | |
{ | |
aThunk | cat ; echo "dollar zero: $?" | |
echo $very | |
aThunk | obviously ; echo "dollar zero: $?" | |
echo $thisIs theEnd | |
} | |
doIts |
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
#!/usr/bin/bash | |
trap "echo outter ERR" ERR | |
trap "echo outter EXIT" EXIT | |
setMode() | |
{ | |
echo set "$*" | |
eval set "$*" | |
export SHELLOPTS | |
} | |
DEFAULTS=$(set +o) | |
MODES=("-o pipefail" "-u" "-e" "-Ee") | |
echo "baseline (default options) " | |
./funcs.sh ; echo '' | |
for i in `seq 1 ${#MODES[@]}`; | |
do | |
echo -n "Test $i: " | |
setMode ${MODES[$i-1]} | |
./funcs.sh || true | |
echo ''; eval ${DEFAULTS}; export SHELLOPTS | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like: