bug-bash
[Top][All Lists]
Advanced

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

Re: Command substitution and exiting from deeply nested subshells


From: Chet Ramey
Subject: Re: Command substitution and exiting from deeply nested subshells
Date: Mon, 07 Oct 2013 10:12:00 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.0

On 10/6/13 8:37 PM, Carlos Pita wrote:

>   I'm not completely sure whether this is a bug or not but it seems
> not possible to immediately exit a shell when an error happens at 2+
> levels of subshell nesting.  Specifically, there is a command at the
> top-level shell waiting for the results of a command substitution.
> This second command in the first subshell is in turn waiting for the
> results of another command substitution. This innermost command fails
> but the awaiting commands still finish their execution as if the error
> never happened. I've tested this with set -e, set -E, an ERR trap,
> explicit exits at each subshell, but to no avail. Below is an example
> to reproduce it.
> 
> Repeat-By:
> 
> trap 'exit 1' ERR
> 
> set -e -E
> 
> function xxx {
>   echo xxx1
>   exit 1
>   echo xxx2
> }
> 
> function yyy {
>   echo $(xxx) yyy
> }
> 
> yyy
> 
> # => xxx1 yyy
> # I wouldn't expect the echo to print any output or execute at all.

$(xxx) is a word expansion, not a command.  Bash will only pay attention to
the exit status of command substitution in one case (x=$(foo)).  This
command substitution doesn't contribute to any other command's exit status,
especially `echo', and `set -e' doesn't cause the shell to pay attention
to it.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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