Why doesn't bash stop when it crashes in a sequence of short-circuited commands?

I see some behavior that does not make sense to me when I run a bash script with an option -ethat has several commands strung together with &&and one of them does not work. I would expect the script to stop on the failed command and return the exit status, but instead, it will just successfully execute the rest of the script.

Here are some examples that make sense to me:

$ false && true; echo $?
1

$ bash -xe -c "false && true"; echo $?
+ false
1

$ bash -xe -c "false; true"; echo $?
+ false
1

And here is one that does not make sense to me:

$ bash -xe -c "false && true; true"; echo $?
+ false
+ true
0

This is where I do not understand what is happening. false && truereturns status 1, so the script should not stop execution and return status 1, how does this happen when the script false; true?

, , , :

$ bash -xe -c "(false && true); true"; echo $?
+ false
1

- ?

+5
2

, && . bash if , set -e.

, , script , : , && , , .

+7

:

, , , , , if, , && & || , , && ||, , , ​​ !

+4

All Articles