3 ms·
Isn't that what set -E is for, when used with set -e? So that an error in the function will also cause the script to terminate. From bash manpage: -E If
by graton 6y ago
Isn't that what set -E is for, when used with set -e?
So that an error in the function will also cause the script to terminate.
From bash manpage:
-E If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The ERR trap is normally not inherited in such cases.
- aidenn0 6y agoNope, the -E has to do with the "trap" command. This example happily echoes "hello" to stdout: #!/bin/bash set -euE -o pipefail FOO=/this/does/not/exist foo() { cd "$FOO" echo hello } if foo; then true; fi
- graton 6y agoWell in that case it appears to be because of using "if foo" But that might have been your point in the first place :) I wasn't aware of the change in behavior with an 'if' statement. As a note, trap ERR had the same behavior as 'set -e' from my quick check. This dies: #!/bin/bash set -euE -o pipefail FOO=/this/does/not/exist foo() { cd "$FOO" echo hello } foo echo We do not reach here