|
From: | Manuel Collado |
Subject: | Re: [bug-gawk] Postdecrementing $NF |
Date: | Sun, 08 Sep 2013 20:19:43 +0200 |
User-agent: | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0 |
El 08/09/2013 19:30, Andrew J. Schorr escribió:
On Sun, Sep 08, 2013 at 02:56:52AM +0200, Adam Zieliński wrote:$NF-- (or even $(NF--) ) - doesn't seem to work as intended.The '$' has higher priority then '--', so I believe $NF-- is equivalent to ($NF)--, which is effectively equivalent to $NF.Instead of giving me a field value and decrementing FN after that, it converts field value to number and then decrements it. Doing the same via variable set to NF works perfectly.However, there does appear to be a problem with $(NF--). Using current git sources: bash-4.1$ echo 1 2 3 4 | gawk '{x = $(NF--); print x; print NF}' 3
Possible explanation: (NF--) returns the "original NF" *after* decrementing NF. So the last field is effectively hidden when $(original NF) is evaluated.
Compare to: bash-4.1$ echo 1 2 3 4 | gawk '{x = $NF; NF--; print x; print NF}' 4 3 and bash-4.1$ echo 1 2 3 4 | gawk '{i = NF; x = $(i--); print x; print i}' 4 3 I don't see any errors from valgrind. I haven't looked further for the cause of this bug... Regards, Andy
Regards, -- Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
[Prev in Thread] | Current Thread | [Next in Thread] |