From owner-freebsd-questions Thu Jun 1 16:53:15 2000 Delivered-To: freebsd-questions@freebsd.org Received: from mta03-svc.ntlworld.com (mta03-svc.ntlworld.com [62.253.162.43]) by hub.freebsd.org (Postfix) with ESMTP id 7DA6137B9C4 for ; Thu, 1 Jun 2000 16:53:11 -0700 (PDT) (envelope-from mark@ukug.uk.freebsd.org) Received: from parish.my.domain ([62.253.84.161]) by mta03-svc.ntlworld.com (InterMail vM.4.01.02.27 201-229-119-110) with ESMTP id <20000601235309.XUVD290.mta03-svc.ntlworld.com@parish.my.domain> for ; Fri, 2 Jun 2000 00:53:09 +0100 Received: (from mark@localhost) by parish.my.domain (8.9.3/8.9.3) id AAA00944 for questions@freebsd.org; Fri, 2 Jun 2000 00:53:08 +0100 (BST) (envelope-from mark) Date: Fri, 2 Jun 2000 00:53:07 +0100 From: Mark Ovens To: questions@freebsd.org Subject: Is awk(1) broken? Message-ID: <20000602005307.B535@parish> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i Organization: Total lack of Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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