3 ms·
Regarding the code... set -euf onecmd --args "$@" The set -u is unneeded, as there are no code variables involved. The set -e is not needed, as there
by txutxu 10y ago
Regarding the code...
set -euf
onecmd --args "$@"
The set -u is unneeded, as there are no code variables involved.
The set -e is not needed, as there is only one command, and the script will return the exit status of such command. Always. And will exit after that command. Always.
The set -f, will disable globbing, which I'm not sure it's what you want, when using a simple wrapper passing "$@" as filenames to gpg...
- jph 10y agoYou're correct. I use -euf as a default for new scripts, until someone asks for relaxing these. I'll remove the -f now because you're right, globbing can be useful.
- Wilya 10y agoNot the author of the code, but personally, I don't see any downside to putting "set -eu" at the beginning of every script I write. These should be defaults.
- nothrabannosir 10y agoI disagree. set -eu should be at the top of every bash script. This is the classic braceless if-guard mistake; leave it out today because you don't need it, forget, add something tomorrow and it breaks.
- switch007 10y agoYou can over-rely on "set -e" however: #!/usr/bin/env bash set -e fail() { false ; echo hello; } if ! fail; then :; fi That outputs "hello" and exits with 0.