[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Postdecrementing $NF
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] Postdecrementing $NF |
Date: |
Sun, 8 Sep 2013 13:30:11 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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
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