|
From: | Eric Blake |
Subject: | Re: trap 'echo "trap exit on ${LINENO}"' EXIT -> wrong linenumber |
Date: | Sat, 18 Sep 2010 14:22:15 -0600 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.3 |
On 09/18/2010 12:18 PM, Chet Ramey wrote:
On 9/18/10 12:57 PM, Eric Blake (cygwin) wrote:On 09/17/2010 06:37 PM, Chet Ramey wrote:I guess you could make a case to not reset $LINENO for the exit trap due to this sentence in Posix (though $LINENO is not Posix):LINENO may be optional in the bare minimum POSIX compliance, but it is certainly specifiedYou're right. I guess the real question is what happens to LINENO when `eval' is executed. bash, ksh93, and zsh do different things, and dash doesn't support LINENO at all. Posix says that trap actions are processed as if executed by eval.
Actually, dash 0.5.6 added rudimentary LINENO support (more precisely, dash.git commit 0df9679 in Aug 2009), all because POSIX requires it. But you are certainly correct about LINENO support differing wildly by shell, even without throwing functions, traps, and eval in the mix:
$ str='echo $LINENO\ \ \ && echo $LINENO echo $LINENO' $ dash -c "$str" 1 1 1 $ bash -c "$str" 3 3 4 $ echo "$str" | dash 1 1 2 $ echo "$str" | bash 4 4 5 -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |