bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] NF variable's value is not affected after reassignment


From: Wladimir Sidorenko
Subject: [bug-gawk] NF variable's value is not affected after reassignment
Date: Tue, 3 Sep 2013 12:45:31 +0200

Dear members of the GNU Awk support team,

Today, I've come across a somewhat unexpected behaviour of Gnu Awk. There, I assign a new value to the NF variable and after that I want to use this new value of NF in a for loop. But in contrast to the BSD awk and mawk, gawk seems to retain the initial value of NF in the loop.

Here is an example:

>echo 'aaa' | gawk '{NF = 10; for (j = 2; j <= NF; ++j){$j = "_"}; print;}'
aaa _

>echo 'aaa' | awk '{NF = 10; for (j = 2; j <= NF; ++j){$j = "_"}; print;}'
aaa _ _ _ _ _ _ _ _ _

>echo 'aaa' | mawk '{NF = 10; for (j = 2; j <= NF; ++j){$j = "_"}; print;}'
aaa _ _ _ _ _ _ _ _ _

>gawk --version
GNU Awk 4.0.1

>uname -srm
NetBSD 6.1 amd64

I could repeat the same difference on Linux 3.4.47-2.38-desktop x86_64 (OpenSuSe).

I send this to you for the case, that it could be a bug.

Kind regards,
Wladimir

reply via email to

[Prev in Thread] Current Thread [Next in Thread]