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?