bug-bash
[Top][All Lists]
Advanced

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

Re: set -e doesn't trigger when command substitutions returns, why?


From: Chet Ramey
Subject: Re: set -e doesn't trigger when command substitutions returns, why?
Date: Wed, 18 Jun 2025 10:24:13 -0400
User-agent: Mozilla Thunderbird

On 6/17/25 9:57 PM, nkkralev--- via Bug reports for the GNU Bourne Again SHell wrote:

When we use set -e, or pass -e to bash itself, -e does process status code 
checks as written in the bash man page.With some testing I think I found a few 
corner cases which I am not sure if they are bugs or not.

They are not. When -e is enabled, bash takes actions based on the exit
status of commands. There is only one case in which the exit status of
a command substitution affects the exit status of a command:

https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_09_01_03


I have added some demonstrations below in Repeat-By below.In test1, we see that 
despite the ls command failing, we see print1 printed, so the error checking of 
set -e was ignored?

The exit status of the command is the exit status of /bin/echo, which is 0.

In test2 we see that when commands are grouped in parenthesis, set -e works 
correctly and we never see print1 shown

The subshell command exits with status 1, set -e is in effect, so the
shell exits.

In test3, we see that the $? value is treated as whatever /bin/echo '' does, 
and that's a success code 0, and the failure of ls was completely ignored.

Correct.

--
``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/



reply via email to

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