bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash errexit shell option does not work in some cases.


From: Robert Elz
Subject: Re: bash errexit shell option does not work in some cases.
Date: Mon, 01 Jun 2020 21:51:54 +0700

    Date:        Mon, 1 Jun 2020 09:16:17 -0400
    From:        Eli Schwartz <eschwartz@archlinux.org>
    Message-ID:  <031b5b39-826a-6523-b03b-b839efe9eb63@archlinux.org>


  | I could not figure out whether the grammar allowed
  | or forbade this this result.

It isn't the grammar, that would affect syntax, it is the semantics
that matter here.

What the current posix spec says is ...

-e When this option is on, when any command fails (for any of the reasons
   listed in Section 2.8.1 or by returning an exit status greater than zero),
[it exits, except for when ...]

In the examples in question that failed, there was a redirection failure.
of a compound command (grouping in the first, while in the 2nd).  Redirection
failures are amongst those listed in 2.8.1.   None of the exceptions apply
in the example cases, so the shell should have exited.

  | So this is actually that unbelievable of unbelievables, a script which
  | is broken because of set -e and it's actually because set -e has a bug?

I don't know what the original script that led to the bug report was,
nor if it makes sane use of -e (very few scripts do .. -e is best left
for make to use) but the examples show bash "issues".   bash (in
non-posix mode) has some differences wrt when the shell exits, and
doesn't - whether these ones fall into that category or not is not for
me to say.

kre

ps: I know of one script that uses -e in a way that works, it consists
of "set -e" and then a whole long list of simple commands, one after
another, where if one fails, none of the following ones makes sense.
I considered changing it, but as that would have just meant adding
" || exit 1" at the end of every line .. literally every line .. or
possibly making a huge "&&" and-or list (with only and) out of it all,
it seemed like a case where "-e" was actually the right approach.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]