3 ms·
i'm surprised it doesn't recommend using set -e /other flags. [http://redsymbol.net/articles/unofficial-bash-strict-mode/ http://redsymbol.net/articles/unoffici
by benmmurphy 8y ago
i'm surprised it doesn't recommend using set -e /other flags. [http://redsymbol.net/articles/unofficial-bash-strict-mode/ http://redsymbol.net/articles/unofficial-bash-strict-mode/] maybe it is not covered because it is not considered 'style' but i think those flags are some of the most important things you can set when writing a bash script. i guess if you are writing scripts that start other things, and then check their error codes it can be annoying because you have turn them off/on.
- falsedan 8y ago`set -e` is basically a way to find where you need better error-handling, not a way to make scripts safe. I'd much rather a crummy script run into trouble calling some new featuref, shrug, and move on to the core business-critical code, instead of erroring out and triggering a bunch of pages.
- ianbicking 8y agoDo you normally protect every command with || exit? cd foobar || exit It's those really small failures that cause shell scripts to do crazy things without set -e.
- falsedan 8y agoWhy wouldn't I rewrite the script to avoid the cd instead? The point of `set -e` isn't to insert all those pointless guards, it's to point out "hey this might fail, so think of a way to do this that doesn't rely on cd". For your extremely thin example, if it (say) removed some files, I would only remove the files from the current directory or an absolute path.
- quotemstr 8y agoPlease don't blindly follow style guides. Use what works right for you. I generally strongly dislike the decions codified in Google "style guides"