I just came upon some shell behaviour I don't understand. TakeI'm trying to run this commandscript:
~$ #!/bin/bash -e
~$
{ echo
"Hello"; false; echo "World";"Doing }
As expected, the output is:
Hellosomething";
After which bash exits with return code 1.
But, when I modify the command like this:
~$ bash -e
~$ { echowill_fail "Hello"; false; # like `false`
echo "World";"Worked";
} || echo "Mars"
I would assume the output would be:
Hello
Mars
Instead it is:
Hello
World"Failed"
And the bash shell is still functional. It seems like || catches the error code of falseTo my surprise, so that -ewill_fail doesn't kill the bash shellfailed, but I openeddid not see "Failed" on my command line, but then instead of executing echo "Mars" it just continues after false"Worked".
What givesWhy did the compound command not exit with error after will_fail failed?