Joined August 2018
·
Posted to
Safer bash scripts with 'set -euxo pipefail'
over 1 year
ago
@kernrad how is that different or new?
He didn't show it with the return code but with "bar" not being printed.
But as far as I can see you just repeat what the entry said.
Did I miss something?
Posted to
Safer bash scripts with 'set -euxo pipefail'
over 1 year
ago
I'd like to suggest adding shopt -s inherit_errexit
.
Without it, command substitution does not inherit the set -e
.
Pipefail is inherited though in any case.
Without that shopt
line, foo=$(gits --version; true); echo $foo
will fail and print an error, but will not make the script fail.
With the option, the script is aborted on that error.
Strangely echo $(gits --version; true)
will not make the script fail either way, but I guess this is a bug.
Which is explicitly mentione in the post