Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Jun 2000 18:08:06 +0100
From:      Mark Ovens <mark@ukug.uk.freebsd.org>
To:        Aaron Jeremias Luz <aaron@csh.rit.edu>
Cc:        questions@freebsd.org
Subject:   Re: Is awk(1) broken?
Message-ID:  <20000608180806.A233@parish>
In-Reply-To: <20000606005300.A371@thud.rochester.rr.com>; from aaron@csh.rit.edu on Tue, Jun 06, 2000 at 12:53:00AM -0400
References:  <20000602005307.B535@parish> <20000606005300.A371@thud.rochester.rr.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jun 06, 2000 at 12:53:00AM -0400, Aaron Jeremias Luz wrote:
> On Fri, Jun 02, 2000 at 12:53:07AM +0100, Mark Ovens wrote:
> > A script I'm writing which reads the ports INDEX file using awk(1)
> > includes this line:
> > 
> > cat INDEX | awk  s=${cmd} 'BEGIN { FS = "|" } {if (index($1, s).....
> > 
> > But this gives the error:
> > 
> > awk: cmd. line:2: fatal: illegal name `BEGIN {FS ' in variable
> > assignment
> 
> If you don't use the -v parameter, you can only specify variable
> assignments on the command line as filenames.  (See the bottom of
> page 4 of the awk man page.)

Yes, I read that but is:

     cat filename | awk s=${cmd} 'BEGIN { FS = "|" }.....

not, in effect, the same as:

     awk s=${cmd} 0 'BEGIN { FS = "|" }.....

0 being stdin? Also in the POSIX COMPATIBILITY section of the manpage
it states that ``-v'' is only to *force* assignment before BEGIN is
executed (to model the behaviour of early versions), irrespective of
whether there are any filenames on the command line, or not, and
whether they are before or after the var=val.

> A quick experiment shows that gawk

gawk, hmmm, the manpage is for gawk but there is no gawk binary, or
even a link to awk, so are you using the version that comes with
FreeBSD?

> will actually interpret a filename that has an equal sign in as an
> assignment -- even if the file exists!
> 
> I am not able to reproduce the error above, but I believe it 
> must involve some problem with shell expansion.

I tried replacing ``s=${cmd}'' with ``s=emacs'' but got the same
results. When I get time I will look at the source for awk because
it's behaviour is definitely different the manpage.
> 
> Hope this helps,
> Aaron
> 
> Disclaimer: My system (a 486 running 3.1-RELEASE) is showing bit-rot,
> and it's time for me to go to bed. :-)

-- 
        ...and on the eighth day God created UNIX
________________________________________________________________
      FreeBSD - The Power To Serve http://www.freebsd.org
      My Webpage http://ukug.uk.freebsd.org/~mark/
mailto:mark@ukug.uk.freebsd.org             http://www.radan.com



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000608180806.A233>