I'm writing a bash script and I'd like it to crash on the first error. However, I can't get it to do this in a specific circumstance I simplified below:
#!/bin/bash
set -Exu
bad_command() {
false
#exit 1
echo "NO!!"
}
(set -o pipefail; bad_command | cat ; echo "${PIPESTATUS[@]}; $?") || false
echo "NOO!!"
The expected behaviour would be a crash of the bad_command
subshell, propagated to a crash of the ()
subshell, propagated to a crash of the outter shell. But none of those crash, and both NOs get printed(!?)
If I uncomment the exit 1
statement, then the NO is no longer printed, but NOO still is(!?)
I tried using set -e
expicitly inside each of the 3 shells (first line in function, first statement after (
, but there's no change.
Note: I need to execute the pipe inside the ()
subshell, because this is a simplification of a more elaborate script. Without the ()
subshell, everything works as expected, no NOs whatsoever with either false
or exit 1
.