-e is great until there’s a command that you want to allow to fail in some scenario.
Yeah, I sometimes do
set +e
do_stuff
set -e
It's sort of the bash equivalent of a
try {
do_stuff()
}
catch {
/* intentionally bare catch for any exception and error */
/* usually a noop, but you could try some stuff with if and $? */
}
I know OP is talking about bash specifically but pipefail isn’t portable and I’m not always on a system with bash installed.
Yeah, I'm happy I don't really have to deal with that. My worst-case is having to ship to some developer machines running macos which has bash from the stone ages, but I can still do stuff like rely on [[
rather than have to deal with [
. I don't have a particular fondness for using bash
as anything but a sort of config file (with export SETTING1=...
etc) and some light handling of other applications, but I have even less fondness for POSIX sh
. At that point I'm liable to rewrite it in Python, or if that's not availaible in a user-friendly manner either, build a small static binary.
I think I mentioned it, but inverse: The only data type I'm comfortable with in bash are simple string scalars; plus some simple integer handling I suppose. Once I have to think about stuff like
"${foo[@]}"
and the like I feel like I should've switched languages already.Plus I rarely actually want arrays, it's way more likely I want something in the shape of