Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: trap ERR



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.








Messages sorted by: Reverse Date, Date, Thread, Author