4 ms·
I set both those options in every script i write. So i do it like this: #! /bin/bash -eu Because i do it in every script, readability and greppability are n
by twic 13y ago
I set both those options in every script i write. So i do it like this:
#! /bin/bash -eu
Because i do it in every script, readability and greppability are not important to me; i just need to apply the flags and get on with the script. Taking up two whole lines for them just adds noise.
If i was more selective in my use of those flags, then i would agree that the long forms were preferable, for the reasons given.
- Hello71 13y agocausing your script to run incorrectly as `bash script`.
- stormbrew 13y agoDoes bash check the flags in the shebang if you run it with bash instead of directly?
- mturmon 13y agoOne drawback with this is that if you, or someone, does % bash script.sh to run your script, then the shebang line will never be seen, and your script will run with -e off. If the "set -e" is explicitly given, this won't happen. As you can guess, I've done this by mistake. One case is after transferring or unarchiving files where execute flags get turned off by mistake. Or using utilities, like job schedulers, that are tricky in whether they run the script as an executable, or via a shell interpreter.