Date: Fri, 2 Jun 2000 00:53:07 +0100 From: Mark Ovens <mark@ukug.uk.freebsd.org> To: questions@freebsd.org Subject: Is awk(1) broken? Message-ID: <20000602005307.B535@parish>
next in thread | raw e-mail | index | archive | help
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 I use ``-v'' thus:
awk -v s=${cmd} 'BEGIN { FS = "|" } {if (index($1, s).....
it works fine. The manpage says that ``-v'' is only for compatibility
with some earlier versions of awk(1) and causes the variable
assignment to take place before the BEGIN block is executed. If ``-v''
is omitted then the variable assignment will happen *after* the BEGIN
block has been executed.
Since the BEGIN block doesn't need ``s'' it should work without
``-v''.
There are 3 possibilities:
1. I've misunderstood the manpage.
2. The manpage is wrong, or ambiguous
3. awk(1) is broken.
Anyone know which?
TIA.
--
...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?20000602005307.B535>
