On 9/25/26 2:05 PM, Robert Elz wrote:
     Date:        Fri, 25 Sep 2026 12:19:53 -0400
     From:        Chet Ramey <[email protected]>
     Message-ID:  <[email protected]>

   | Not quite. It suppresses the immediate exit in a non-interactive shell.

Yes, that's what I was intending to say!

Yep, just clarifying for others.


   | Some other internal mechanism, yes.

It had to be .. though I'm not sure I follow what you said in your reply
to the OP..  execfail does avoid exit in *non*-interactive shells, but
causes a 127 exit status (for the example case anyway, I guess it might
be 126 in some other cases).   errexit (-e) causes the shell to exit if
a non-zero exit status happens (in simple commands anyway).   Except when
it is being ignored by one of the things that makes that happen.

All this is true, and, as the OP noted, both have to be enabled to exhibit
this behavior.

The low-level error-printing function that understands `errexit' was being
called by another function that exec used to report that the file didn't
exist. Now, if `errexit' is set, this function prints an error message and
exits.

If it's not set, but `execfail' is, `exec' knows the error happened and
arranges not to exit. If neither one is set, `exec' again knows the error
happened and exits.

If it's set and `execfail' isn't, the error function prints its message and
exits, but that's what's supposed to happen and no one is the wiser. So you
can see the problem: if `errexit' and `execfail' are both set, the error
function prints the message and exits, never giving `exec' the chance to
inhibit it.

The real problem was having the second function call the first, which
exits the shell unconditionally if `errexit' is enabled. As I hinted to
the OP, this is how it's been forever (or at least 1991).

The easy part is changing that second function. The rest is analyzing code
paths and making sure the shell exits (or doesn't) appropriately in the
places that second function is called.
   | It's actually an easy change.

OK, but so is avoiding using -e and all the problems and weirdness that
comes with it.

Sure, yeah, but I can't do a lot about the inertia and advice to use
`set -euo pipefail' that's out there. I can fix this problem.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [email protected]    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to