Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Stop script if one command returns != 0
On Wed, 14 May 2014 16:21:55 +0200
Florian Lindner <mailinglists@xxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author