4 ms·
It's always been odd that Bash has hundreds of options for controlling its behaviour in non-standard ways, via "set", "shopt" and environment variables, but it'
by jlokier 4y ago
It's always been odd that Bash has hundreds of options for controlling its behaviour in non-standard ways, via "set", "shopt" and environment variables, but it's never had an option to make "-e" do the obviously natural behaviour,,
I encountered the "you can't enable -e" problem years ago in a complex build system that used Bash to build embedded sysem components. The scripts were all designed on the assumption that "set -eu -o pipefail" would cause early exit on any failing commands as if doing the equivalent of "exit $?" or "return $?", and of course it is not reliable, as your example shows.
The very surprising behaviour of "set -e" inside functions was not noticed for a long time while the system was being written and used. When it was noticed, "set -e" was added inside the functions because that seemed to work for the Bash version at the time, then later it stopped working.
- chubot 4y agoit's never had an option to make "-e" do the obviously natural behaviour,, This is harder than it sounds! :) There's arguably not a natural behavior for shell, because $? is overloaded in Unix. It can mean success/failure or it can mean true/false/error. https://www.oilshell.org/release/latest/doc/error-handling.html#what-does-mean https://www.oilshell.org/release/latest/doc/error-handling.h... Oil introduces some new idioms that led you distinguish between the two paradigms, so it's best to change the way you write scripts. It's not something bash can magically fix. https://www.oilshell.org/release/latest/doc/idioms.html#error-handling https://www.oilshell.org/release/latest/doc/idioms.html#erro... That said, just running your scripts with Oil will flag problems, acting like a ShellCheck at runtime, catching things that ShellCheck can't. See the sibling reply for a demo, and this comment: https://news.ycombinator.com/item?id=33117337 https://news.ycombinator.com/item?id=33117337