Re: Unexpected behavior from combination of errexit and execfail
From:
Chet Ramey
Subject:
Re: Unexpected behavior from combination of errexit and execfail
Date:
Fri, 25 Sep 2026 12:19:53 -0400
User-agent:
Mozilla Thunderbird
On 9/25/26 6:08 AM, Robert Elz wrote:
Date: Fri, 25 Sep 2026 15:10:30 +1200
From: Martin D Kealey <martin@kurahaupo.gen.nz>
Message-ID:
<CAN_U6MXvXrkhQJN7hzdrnTc4v6T4cm65MczxdqcevTazhV2V2g@mail.gmail.com>
| The significant change isn't any combination of «set -e», «set -o errexit»
| and/or «shopt -s execfail», but rather the insertion of «exec».
You really should start paying a little more attention. You completely
ignored the shopt -s execfail, which has the purpose of causing the exit
on failure of exec to not happen in interacive shells.
Not quite. It suppresses the immediate exit in a non-interactive shell.
Interactive shells -- in the absence of other options, like `errexit' --
don't exit if `exec' fails.
There clearly is an issue here - my guess is that the execfail shopt is
implemented by running the exec in a subshell (though how that would work
when the exec works I have no idea) - or some similar internal mechanism,
Some other internal mechanism, yes.
As a bug worth fixing, I'd put this one way down the list, it is easy to
avoid - just don't use -e. Ever.
It's actually an easy change.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/