zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: Stop script if one command returns != 0
Date: Wed, 14 May 2014 15:35:44 +0100	[thread overview]
Message-ID: <20140514153544.44c4cd7b@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <355857b792fd08eade06510fd648684d@xgm.de>

On Wed, 14 May 2014 16:21:55 +0200
Florian Lindner <mailinglists@xgm.de> wrote:
> Ok, just a second after the mail I learned about set -e. The problem is 
> when sourcing the script it kills my entire shell.
> 
> I tried installing a trap
> 
> trap 'echo "Hallo"' TERM INT ABRT EXIT
> 
> (just a as first shot, trying to catch almost anything) but changed 
> nothing.
> 
> Any ideas how do deal with that?

Wrap your sourced file in a function and use the zsh-specific option
ERR_RETURN.

source_with_err_return() {
   setopt localoptions errreturn
   source "$@"
}


Test:

% >script
print Got here
false
print But not here
% source_with_err_return ./script
Got here


& for the paranoid:


% fn2() {
function> source_with_err_return ./script
function> false
function> print Got here OK as ERR_RETURN is no longer on.
function> }
% fn2
Got here
Got here OK as ERR_RETURN is no longer on.


pws


  reply	other threads:[~2014-05-14 14:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-14 14:01 Florian Lindner
2014-05-14 14:19 ` Chris Johnson
2014-05-14 14:20 ` Peter Stephenson
2014-05-14 14:31   ` Florian Lindner
2014-05-14 15:10     ` Bart Schaefer
2014-05-14 16:22   ` Roman Neuhauser
2014-05-14 14:21 ` Florian Lindner
2014-05-14 14:35   ` Peter Stephenson [this message]
2014-05-14 14:49     ` Peter Stephenson

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=20140514153544.44c4cd7b@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).