[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: Jean-Philippe Guérard
Subject: Re: Possible bug in gawk: local FS not used
Date: Tue, 12 May 2009 00:14:14 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Le 2009-05-11 23:31:56 +0200, Dave B écrivait :
> 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).

No problem :)

> 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
> parameter:
> $ 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.

That's what I did in the end :) But I spent a lot of time wondering why 
the value of FS was not taken in account.

An error message would really have been helpful here, especially as 
printing the FS value gave me the expected result. Otherwise, nothing to 
say, the gawk behaviour was correct.

Thanks again for your help.


Jean-Philippe Guérard

reply via email to

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