4 ms·
A worse idea would be to run bash scripts adhoc without at least `set -u`. There is an unofficial bash “strict mode”, overlooked and undervalued: set -euo pip
by nrvn 2y ago
A worse idea would be to run bash scripts adhoc without at least `set -u`.
There is an unofficial bash “strict mode”, overlooked and undervalued:
set -euo pipefail
Just use it everywhere and use shellcheck for scripts.
- evgpbfhnr 2y ago`set -e` is evil: https://web.archive.org/web/20240511180116/https://mywiki.wooledge.org/BashFAQ/105 https://web.archive.org/web/20240511180116/https://mywiki.wo... (wooledge wiki doesn't seem to load for me for some reason so archive.org it is)
- hyperhopper 2y agoThis perfectly illustrates the problem with bash. Somebody did something the straightforward way which worked. A solution is given on a better way, but that also has a problem that somebody else didn't know about. Bash let's you do anything and have it kind of work but you never know how many footguns you're setting up for yourself.
- anal_reactor 2y agoI hate bash
- hannibalhorn 2y agoThat's an interesting link and an argument I hadn't seen before. In my "real world" usage, I've found "bash strict mode" incredibly useful, especially when scripting things that others will be modifying. It just avoids all of the "somebody forgot an error check", "there's a typo in a variable name", etc., type errors. And pouring through logs to figure out what actually went wrong in CI/CD is brutal. Looking at the examples: - I don't generally do arithmetic in bash, that's a sign of "time to change language" - Also generally use `if ...; then ...; fi` instead of `test ... && ...` If you do the advanced type of scripting that somebody who writes a Bash FAQ does, I'm sure `set -e` can be annoying. But once you learn a couple simple idioms y(covered on the original "bash strict mode" page) you don't have to know much more to have fairly robust scripts. And future maintainers will thank you for it!