3 ms·
-eu? Yes. -o pipefail? Maybe not, for two reasons: 1. Pipefail is a bashism, and doesn't exist on Ubuntu's /bin/sh or Busybox /bin/sh (common on embedded Linux
by nrclark 3y ago
-eu? Yes. -o pipefail? Maybe not, for two reasons:
1. Pipefail is a bashism, and doesn't exist on Ubuntu's /bin/sh or Busybox /bin/sh (common on embedded Linux systems)
2. Pipefail invalidates some common shell patterns like "grep _something_ | xargs -r CMD".
Pipefail is nice in some circumstances for sure. But it's probably not great advice to automatically copypasta into the top of every shell-script.
- koolba 3y ago> 1. Pipefail is a bashism, and doesn't exist on Ubuntu's /bin/sh or Busybox /bin/sh (common on embedded Linux systems) I wasn't suggesting for a generic posix shell. It's explicitly for bash. If you're going to dumb down to pure posix, it's even more painful as you can't even have local function variables. > 2. Pipefail invalidates some common shell patterns like "grep _something_ | xargs -r CMD". That type of situation is the exception, not the rule. The more common situation is "foo some-input.txt | bar" and you want it to fail if foo fails. > Pipefail is nice in some circumstances for sure. But it's probably not great advice to automatically copypasta into the top of every shell-script. I'd much rather have that type of failure than an inadvertent continuation of a script when something early in a pipeline failed.
- da39a3ee 3y agoI don't agree on -e: see my comment higher up in the thread. It might be ok if you're hyper-aware, but recommending it to others will leave them baffled and confused in situations like that in my example where a non-zero exit is within the bounds of normal behavior of the script.