How can explain this bash behavior ? Do not exit on '&&' statements ?
# bash -xe
bash-4.1# trap 'echo ERROR' ERR
+ trap 'echo ERROR' ERR
bash-4.1# false && true
+ false
bash-4.1# false && false
+ false
bash-4.1# false || true
+ false
+ true
bash-4.1# false || false
+ false
+ false
++ echo ERROR
ERROR
Read carefully what man bash says about set -e:
The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test following the if or elif reserved words, part of any command executed in a
&&or||list except the command following the final&&or||[...]
Emphasis mine.
Detailed explanation: When running false && false, the first false makes the whole command fail because of short circuiting, and as it's not the last command in the construct, its exit status is ignored. In case of false || false, the first false makes the second false run which fails as well, but its exit status isn't ignored, as it's the last command in the construct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With