On Mon, Apr 03, 2023 at 10:30:29AM -0400, Chet Ramey wrote: > On 3/31/23 10:20 PM, Zev Weiss wrote: > > > Bash Version: 5.2 > > Patch Level: !PATCHLEVEL! > > Release Status: release > > > > Description: > > > > When 'set -e' is enabled, file-content substitutions of the form $(<...) > > cause an immediate exit even when the subsitution is in a conditional > > context such as the condition of an 'if' statement or the left operand > > of the '||' operator. > > It's always been a (fatal) redirection error, but, as you suspect, has a > different effect now that $(<file) is run without forking. I'll change it > to a non-fatal failed word expansion for this case.
Very interesting. I agree that it makes more sense as a non-fatal shell error. I am a bit surprised that the problem only occurs when errexit is on, and not when it is off though. In any case, a possible workaround, for now, is to use the usual technique to "catch" fatal errors: # in standard mode if ! eval 'x=$(</nosuchfile)'; then x='' echo hello fi Or: # in POSIX mode or standard mode if ! command eval 'x=$(</nosuchfile)'; then x='' echo hello fi emanuele6