4 ms·
I use set -e or not based on the needs of the script. Many times I want the script to continue and sometimes I don't. Sometimes I don't set until partway down
by mchahn 11y ago
I use set -e or not based on the needs of the script. Many times I want the script to continue and sometimes I don't. Sometimes I don't set until partway down the script so the top isn't strict. I wouldn't want to set it on every script.
- skuhn 11y agoI've encountered a fair number of people who blindly set -eu on every script as a matter of course, as suggested by the author here. While this article goes through a bunch of the pitfalls, in my experience people often fail to account for the many (sometimes unintuitive) ways this can cause an abrupt exit. Sometimes stopping halfway through is just as bad as continuing under false assumptions, particularly if the script is so simplistic that it isn't obvious to the user that it exited midway through. I almost never use -e, and as a result I have to stay vigilant and test return codes all over the place. I prefer that to the kludge of forcing everything to return zero and I think it produces overall better results. Ultimately you want to handle an error, not just abort, and -e doesn't do much to promote handling properly.
- vacri 11y agoAbsolutely, but it's a good general default. I don't want set -e on my backup aggregator script (if one sync fails, keep doing the others), but for most other scripts it's good to have.\ I've had mixed luck with set -e combining with trap ERR though - they seem to conflict with each other and I don't have the shell knowledge to sort it out.