I want my bash scripts to detect execution errors and exit.
For the longest time I've been using the try/yell/die
approach as seen here.
yell() { echo "$0: $*" >&2; }
die() { echo -e "\e[31m$*\e[0m"; exit 1; }
try() { "$@" || die "cannot $*"; }
However this requires me to wrap my commands line this;
try curl https://blah.com | try bash
It seems the better approach would be to use;
set -e
set -o pipefail
set -E
Are there any downsides to using the set
approach, opposed to try/yell/die
?