Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.unix.shell > #4872
| 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 07:34 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <20120502063438.GA10446@chaz.gmail.com> (permalink) |
| References | <jnpk36$jqs$1@reader1.panix.com> |
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 }
>
> How can I mimic the behavior of "set -e" within a subshell? (Or
> within a function, for that matter?) (I realize that I can always
> append "|| exit 1" to every command, but this is precisely what
> I'd like to avoid.)
[...]
Try
zsh -ec '
cmd1
cmd2...
' || ...
Or:
(
setopt nodebugbeforecmd
TRAPDEBUG() { ((!$?)) || exit; }
cmd1
cmd2...
) || ...
I personally wouldn't touch "set -e" with a barge pole, and
would use some « || die '...' »
With die() being a function that takes an optional argument to
display on stderr and exits with a non-zero exit status.
--
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