Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.unix.shell > #4875
| From | Stephane Chazelas <stephane.chazelas@gmail.com> |
|---|---|
| Newsgroups | comp.unix.shell |
| Subject | Re: [zsh] How to mimic errexit within subshell (or function)? |
| Date | 2012-05-02 14:29 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <20120502132926.GF10446@chaz.gmail.com> (permalink) |
| References | <jnpk36$jqs$1@reader1.panix.com> <20120502063438.GA10446@chaz.gmail.com> <f8n779-hk5.ln1@leafnode-msgid.gclare.org.uk> |
2012-05-02 13:51:59 +0100, Geoff Clare:
> Stephane Chazelas wrote:
>
> > 2012-05-01 21:20:38 +0000, kj:
> >>
> >> The following scheme doesn't work as expected: despite the set -e
> >> (errexit), the subshell does not exit on error (it just goes on to
> >> execute the next command):
> >>
> >> #!/usr/bin/zsh
> >> (
> >> set -e
> >> cmd0...
> >> cmd1...
> >> cmd2...
> >> ...
> >> echo "$0: done"
> >> ) || { echo "$0: failed" && exit 1 }
>
> > Try
> >
> > zsh -ec '
> > cmd1
> > cmd2...
> > ' || ...
>
> Or try
>
> (
> set -e
> cmd1
> cmd2...
> )
> test $? -eq 0 || ...
>
> (I don't have zsh, but that works in ksh, bash and dash).
[...]
Indeed, though I had assumed "set -e" was also in effect in the
rest of the script (and "|| ..." was so that the failure of the
subshell wouldn't exit the script)
In that case, you can temporarily disable "set -e"
...
set +e
(
set -e
cmd1
cmd2...
)
rc=$?
set -e
[ "$rc" -eq 0 ] || ...
--
Stephane
Back to comp.unix.shell | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[zsh] How to mimic errexit within subshell (or function)? kj <no.email@please.post> - 2012-05-01 21:20 +0000
Re: [zsh] How to mimic errexit within subshell (or function)? Stephane Chazelas <stephane.chazelas@gmail.com> - 2012-05-02 07:34 +0100
Re: [zsh] How to mimic errexit within subshell (or function)? Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2012-05-02 13:51 +0100
Re: [zsh] How to mimic errexit within subshell (or function)? Stephane Chazelas <stephane.chazelas@gmail.com> - 2012-05-02 14:29 +0100
Re: [zsh] How to mimic errexit within subshell (or function)? kj <no.email@please.post> - 2012-05-02 19:33 +0000
Re: [zsh] How to mimic errexit within subshell (or function)? Stephane Chazelas <stephane.chazelas@gmail.com> - 2012-05-02 20:53 +0100
Re: [zsh] How to mimic errexit within subshell (or function)? Martin Vaeth <vaeth@mathematik.uni-wuerzburg.de> - 2012-05-02 10:30 +0000
Re: [zsh] How to mimic errexit within subshell (or function)? kj <no.email@please.post> - 2012-05-02 19:09 +0000
Re: [zsh] How to mimic errexit within subshell (or function)? kj <no.email@please.post> - 2012-05-02 19:12 +0000
Re: [zsh] How to mimic errexit within subshell (or function)? Stephane Chazelas <stephane.chazelas@gmail.com> - 2012-05-02 20:27 +0100
Re: [zsh] How to mimic errexit within subshell (or function)? kj <no.email@please.post> - 2012-05-03 18:20 +0000
csiph-web