[Top][All Lists]

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

Re: Possible bug in gawk: local FS not used

From: Dave B
Subject: Re: Possible bug in gawk: local FS not used
Date: Mon, 11 May 2009 23:31:56 +0200
User-agent: Thunderbird (X11/20090420)

Jean-Philippe Guérard wrote:

>>> If I understand well, when parsing the input line, the global FS 
>>> variable is always used, even if a local FS exists.
>>> Could you confirm if this is a bug or intended?
>> Please see the section "Advanced Notes: Changing FS Does Not Affect the
>> Fields" in the GNU awk user's guide.
> I've already read that section, but it does not seem to apply here:
> I'm setting the value of FS then calling getline.

Ah, now I see what you mean (sorry, I read your previous message too quickly).

Many awk implementations seems to behave like gawk here (including bell labs
awk and busybox awk); mawk aborts with an error if FS is used as a function

$ mawk 'function foo(FS){print "hello"} BEGIN{foo()}'
mawk: line 1: syntax error at or near $

sure enough, changing the FS with anything else makes the error disappear.
(btw, it produces the same error also with RS)

To the point, the POSIX standard says this:

"The same name shall not be used as both a function parameter name and as
the name of a function or a special awk variable"

which probably makes mawk the more correct implementations in this regard.
Is there a special need why you need to use FS as a local variable?
Depending on your needs, you may be able to obtain the same result by saving
FS, changing it, and restoring it afterwards.


reply via email to

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