[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: command substitution is stripping set -e from options
From: |
Chet Ramey |
Subject: |
Re: command substitution is stripping set -e from options |
Date: |
Thu, 8 Oct 2015 11:26:08 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 10/5/15 5:37 PM, Christoph Gysin wrote:
>> The parent shell (the one that enabled -e) should be the one to make the
>> decision about whether or not the shell exits. The exit status of the
>> command substitution doesn't make a difference except in one special case,
>> so inheriting errexit and exiting (possibly prematurely) doesn't really
>> help the parent decide whether or not to exit.
>
> I'm not sure I fully understand.
>
> The parent shell should be the one to decide if the script is supposed
> to abort on any unsuccessful exit status. Command substitution should
> not change that. The parent shell decided via set -e that it wants to
> exit immediately on error.
Sure, the parent shell should make this decision. Consider that, other
than one special case, the exit status of a command substitution has no
effect on whether a command succeeds or fails, and whether or not the
parent shell exits. If you have something like
set -e
command -f $(command that generates a filename) -opts other arguments
and the command substitution inherits the -e option and exits
prematurely, the parent shell will not inspect its exit status and will
happily execute the command, possibly with faulty data. This is simply
how command substitution works.
> If you don't want to fix this for backwards compatibility, is there
> anyway we could change that behaviour explicitly? I.e. with another
> option? Avoiding command substitution isn't really an option, and this
> essentially disables the whole point of set -e.
I think you're overlooking what I referred to above: that the exit status
of a command substitution doesn't have any effect on whether the parent's
command succeeds or fails except in one case: the right-hand-side of an
assignment statement that is the last assignment in a command consisting
only of assignment statements. To say that it `disables the whole point
of set -e' is a considerable overstatement.
--
``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/
- Re: command substitution is stripping set -e from options, (continued)
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/08
- Re: command substitution is stripping set -e from options, Eric Blake, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options,
Chet Ramey <=
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/10
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/13
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/15
- Re: command substitution is stripping set -e from options, Linda Walsh, 2015/10/15