[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
using `set -e' in a subshell
From: |
Jim Meyering |
Subject: |
using `set -e' in a subshell |
Date: |
Sun, 27 Mar 2005 19:43:33 +0200 |
Hi,
Is the following behavior intended?
I was surprised by the behavior of bash/zsh/ash/dash/pdksh,
yet Solaris 5.9's /bin/sh does what I expected:
# Solaris 5.9's /bin/sh
$ echo a; (set -e; false; echo foo) && echo b
a
# Yet bash/zsh/ash do this:
$ echo a; (set -e; false; echo foo) && echo b
a
foo
b
The POSIX spec for set's -e option says the following,
so it all comes down to how you interpret being ``part of
an AND or OR list'':
-e When this option is on, if a simple command fails for any of the
reasons listed in Section 2.8.1 (on page 46) or returns an exit status
value >0, and is not part of the compound list following a while,
until, or if keyword, and is not a part of an AND or OR list, and is
not a pipeline preceded by the ! reserved word, then the shell shall
immediately exit.
My take was to consider the subshell commands in isolation,
where I expected the `set -e' to take effect. There, the simple
command `false' fails, so I expected that subshell to exit nonzero
and not print `foo'.
I'm using:
$ bash --version
GNU bash, version 3.00.16(1)-release (i386-pc-linux-gnu)
- using `set -e' in a subshell,
Jim Meyering <=