Re: [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero

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

 



On 06/28/2010 01:22 AM, Cristian Ionescu-Idbohrn wrote:
>> Has bash's behaviour changed recently (I'm using an ancient
>> version)?

Yes - bash 4.1 tries harder to be compliant with the recent Austin Group
interpretations (and more like ksh).

> 
> bash 3.2.39 and 4.0.37 are behaving as dash without the suggested
> patch.  Still.  What is the correct behaviour?  That should be the
> essential matter IMO, not what others do.  So, why should this fail:
> 
> 	$ dash -c 'set -e; false; echo here'
> 
> and this succeed?
> 
> 	$ dash -c 'set -e; (false); echo here'

According to the Austin Group:
http://austingroupbugs.net/view.php?id=52

the desired behavior is:

Replace the description of -e with:

  -e When this option is on, when any command fails (for any of the
      reasons listed in [xref to 2.8.1] or by returning an exit status
      greater than zero) the shell immediately shall exit with the
      following exceptions:

      1) The failure of any individual command in a multi-command
          pipeline shall not cause the shell to exit. Only the
          failure of the pipeline itself shall be considered.

      2) The -e setting shall be ignored when executing the compound
          list following the while, until, if, or elif reserved word,
          a pipeline beginning with the ! reserved word, or any
          command of an AND-OR list other than the last.

      3) If the exit status of a compound command other than a
          subshell command was the result of a failure while -e was
          being ignored, then -e shall not apply to this command.

      This requirement applies to the shell environment and each
      subshell environment separately. For example, in

          set -e; (false; echo one) | cat; echo two

      the false command causes the subshell to exit without executing
      echo one; however, echo two is executed because the exit status
      of the pipeline (false; echo one) | cat is zero.

Per these rules, both 'set -e; false; echo here' and 'set -e; (false);
echo here' are silent in bash 4.1.  The fact that dash is not silent
when a subshell exits with non-zero status is at odds with the above
Austin Group ruling.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux