Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!elsie!ncifcrf!randy From: randy@ncifcrf.UUCP (The Computer Grue) Newsgroups: comp.unix.wizards Subject: Re: #! magic number Message-ID: <136@ncifcrf.UUCP> Date: Mon, 29-Jun-87 09:33:03 EDT Article-I.D.: ncifcrf.136 Posted: Mon Jun 29 09:33:03 1987 Date-Received: Wed, 1-Jul-87 01:56:43 EDT References: > <2211@bunker.UUCP> <1097@mtune.ATT.COM> <1895@vdsvax.steinmetz.UUCP> Organization: NCI Supercomputer Center, Frederick, MD Lines: 51 Summary: Spaces seem to cause a problem In article <1895@vdsvax.steinmetz.UUCP>, barnett@vdsvax.steinmetz.UUCP (Bruce G Barnett) writes: > Yes, I did try #!/bin/awk -f > > I STILL get the "bail" error: > Exhibit A, Ultrix 1.2: > > csh >cat t.awk > #!/bin/awk -f > BEGIN { print "Begin"} > { > print; > } > END { print "End"} > csh> awk -f t.awk Begin > End > csh> t.awk > awk: syntax error near line 1 > awk: bailing out near line 1 > You are not going to f**king believe this. I got curious enough about your question to start fiddling (I use several awk 'shell scripts' and they work fine for me) and I think I figured out what the problem is. You have a space (that's right, hex 0x20, char ' ', whatever) immediately after your '-f'. This seems to be a problem because the kernel is passing '-f ' (as opposed to '-f', which is what the shell would pass it) to awk as it's first argument and it doesn't seem to know how to deal with a space immediately after a flag. Since the argument parsing is done in the kernel for the 'interpeter line' of shell scripts and in the shell for straight command line arguments, awk's getting a little hosed when called through the 'exec' mechanism. I confirmed this hypothesis two ways. First, I deleted the space at the end of the first line and Bruce's program runs fine. That is to say, the program: ------------------------- #!/bin/awk -f BEGIN { print "Begin"} { print; } END { print "End"} --------------------- works fine for me (check it; no space) where the original program does not. Second, I invoked "awk '-f ' awk.inp" and reproduced the syntax error message. Weird. I'm not sure whether I'd call this a bug in the kernel processing of the '#!' magic number, or whether awk should be able to handle '-f ' as an argument. Bad synergy. -- Randy Smith -- Randy Smith @ NCI Supercomputer Facility c/o PRI, Inc. PO Box B, Bldng. 430 Phone: (301) 698-5660 Frederick, MD 21701 Uucp: ...!seismo!elsie!ncifcrf!randy