From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: trap ERR
Date: Tue, 21 Feb 2017 07:52:02 -0800 [thread overview]
Message-ID: <d2dab44b-2d0c-eae9-5c3d-86d9f37b0cc3@eastlink.ca> (raw)
In-Reply-To: <dea65262-b9f0-5b34-3545-ed98d381aded@eastlink.ca>
On 20/02/17 10:08 PM, Ray Andrews wrote:
> I haven't played around with traps much, but trying this in a script:
>
> trap 'echo ERROR at $0 $LINENO; return' ERR
>
> cp file1/tmp
> cp no_such_file/tmp
> cp file2/tmp
>
> # trap '' ERR
>
> I want to return with the message at any error, and it does return,
> but it seems that the trap remains in effect which puzzles me since
> when a script quits, I expect things to be returned to stock, no? The
> commented line kills the trap fine, but of course if I return at the
> first error, it's never executed.
>
> Also, I'd expect to 'exit' a script, but it ends up killing the whole
> terminal. I'm used to using 'return' but now that I stop to think
> about it, that should be wrong, no?
Pardon, that was a moronic question. I'm so used to sourcing scrips
that I mostly forget that there is any such thing as executing them and
I'm sourcing automatically even when I think I'm executing -- I type the
little dot so fast I don't even notice it. I don't execute because I
don't know how to have access to my functions inside an executed
script. Can I? If so, all the above difficulties go away.
>
>
>
>
next prev parent reply other threads:[~2017-02-21 16:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-21 6:08 Ray Andrews
2017-02-21 15:52 ` Ray Andrews [this message]
2017-02-21 16:41 ` Peter Stephenson
2017-02-21 16:56 ` Ray Andrews
2017-02-21 17:30 ` Bart Schaefer
2017-02-21 19:57 ` Ray Andrews
2017-02-22 4:21 ` Bart Schaefer
2017-02-22 4:39 ` Ray Andrews
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=d2dab44b-2d0c-eae9-5c3d-86d9f37b0cc3@eastlink.ca \
--to=rayandrews@eastlink.ca \
--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).