bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: parsing getline var argument


From: Joel E. Denny
Subject: Re: parsing getline var argument
Date: Fri, 17 Aug 2007 23:39:29 -0400 (EDT)

On Mon, 13 Aug 2007, Aharon Robbins wrote:

> > I then ran:
> >
> >   % ./gawk '{getline $4; print $4;}' > stdout
> >   line 1
> >   line 2
> >   % cat stdout
> >   line2
> >
> > Recent releases of GAWK behave in the same way, but this behavior differs 
> > from /usr/bin/awk under Solaris 10:
> >
> >   % /usr/bin/awk '{getline $4; print $4;}' > stdout
> >   line 1
> >   line 2
> >   % od -c stdout
> >   0000000  \n
> >   0000001
> >
> > What is the correct behavior?  Is `getline $4;' a GNU extension?  Or is 
> > the behavior undefined here?
> 
> Gawk is correct. The argument to getline is an lvalue, which receives
> the contents of the line just read in.  Using a field is a very ill-defined
> kind of thing to do

In what way is it ill-defined?  The main motivation behind my questions is 
to find out if this is an obscure or ill-defined area of AWK and thus 
won't make as good of a real-world parsing example.

It dawned on me recently to check the Open Group specification for AWK.  
It seems to agree with Gawk's syntax analysis of the examples I included 
in my last post, and it agrees that $4 is an lvalue.  Its first few 
paragraphs seem to define the effect of assigning $0, $1, etc fairly 
clearly.

> , but Solaris awk output is broken.  That is a very OLD
> awk anyway, and you should compare the Solaris /usr/xpg4/bin/awk, which
> happens to get it right. So does mawk.

Thanks for that information.  Thanks to Juergen as well.




reply via email to

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