I have a multi-step check before deciding whether to execute some code. In words: “The code should be executed, if a guard file does not exist, and there are no files newer than a guard file.”
I tried to express this as follows:
#!/usr/bin/env bash
set -e -E -u -o pipefail
if (
test -e ".guard"
echo "Checking for changed source files..."
find src -newer ".guard" -exec false ; -quit
) then
echo Building...
fi
set -e
means, that the first failing command should fail the shell. set -E
means, that subshells should inherit the behavior. And yet, even when .guard
does not exist, the echo
is executed.
Even more so, set -e
seems to be ignored even if set in the condition-subshell.
>>> if(set -e; echo 0; false; echo 1;); then echo 2; else echo 3; fi
0
1
2
Why does this happen?
3