All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: dash@vger.kernel.org
Cc: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Subject: Re: [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero
Date: Mon, 28 Jun 2010 07:16:38 -0600	[thread overview]
Message-ID: <4C28A0B6.5010305@redhat.com> (raw)
In-Reply-To: <1006280909240.5913@somehost>

[-- Attachment #1: Type: text/plain, Size: 2357 bytes --]

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@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

  reply	other threads:[~2010-06-28 13:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-14  9:56 [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero Gerrit Pape
2010-06-28  7:02 ` Herbert Xu
2010-06-28  7:22   ` Cristian Ionescu-Idbohrn
2010-06-28 13:16     ` Eric Blake [this message]
2010-07-05  8:26       ` Herbert Xu
2010-07-06  9:51 ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C28A0B6.5010305@redhat.com \
    --to=eblake@redhat.com \
    --cc=cristian.ionescu-idbohrn@axis.com \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.