Klemens Nanni <[email protected]> wrote:
> On Tue, Sep 06, 2022 at 05:50:31PM +0000, Lucas wrote:
> > Sorry for the noise. I wasn't aware that `set -e` only takes into
> > consideration the last command in an AND-OR list and not the exit status
> > of the AND-OR list itself.
> 
> What is the status of the list itself?
>       A && B
> returns the exit code of A if it is non-zero or the exit code of B if
> A exited non-zero.

It's becoming a bit off-topic to the patch itself, but...

What you say is correct. The problem is the interaction with set -e.

If you have scripts

        # test1.sh
        false
        echo $?

and
        # test2.sh
        false && true
        echo $?

both `sh test1.sh` and `sh test2.sh` will output "1". If instead are
run as `sh -e test1.sh` and `sh -e test2.sh`, only test2.sh will output
"1". My original understanding was that neither should output at all.
Behaviour is the same using ksh instead of sh. The normative reference
is 
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set .
It's just another case of `set -e` acting unintuitively.

> Oh dear... these mistakes slip in if you test a diff on one machine and
> reconstruct it on another rather than copying over a patch file.

Been there done that.

Reply via email to