[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Doc of "set -e" should mention non-locality
From: |
Dan Douglas |
Subject: |
Re: Doc of "set -e" should mention non-locality |
Date: |
Fri, 29 Jun 2012 18:03:13 -0500 |
User-agent: |
KMail/4.8.3 (Linux/3.4.2-pf+; KDE/4.8.3; x86_64; ; ) |
On Thursday, June 28, 2012 02:37:17 PM Rainer Blome wrote:
> The implementation of "set -e" does not respect "lexical nesting".
> This can be very surprising.
None of the "set" options do, nor does the ERR trap. That would make this the
exception. Here's a workaround (untested).
sete() {
[[ $- == *e* ]] && return 1
trap "$(</dev/stdin)" RETURN
} <<EOF
if [[ $FUNCNAME != \$FUNCNAME ]]; then
set +e
trap - RETURN
else
set -e
fi
EOF
This will "set -e" in only the scope of the caller. It gets a bit more
complicated if you want to use this RETURN feature more extensively and
preserve other possible RETURN traps, but most people won't have to worry
about that.
--
Dan Douglas
signature.asc
Description: This is a digitally signed message part.