braun@dri.com (Kral) (04/12/91)
Can someone tell me if this is a known bug (I'm quite sure you'll tell me if
I'm doing something stupid here)? It seems that either csh or awk is barfing
on the '#!' majik number. Here's my test awk script:
drivax> cat test.awk
#! /bin/awk
#
{
print "This is a test"
}
###
When I run it explicitly invoking awk, I get what you would expect (ie, nothing
- but it doesn't complain about anything either):
drivax> awk -f test.awk </dev/null
drivax>
But if I invoke it directly from the shell, I get:
drivax> ./test.awk
awk: syntax error near line 1
awk: bailing out near line 1
drivax>
Am I misunderstanding the operation of '#!'? Or is not not fully implemented
in 4.1 Ultrix?
--
kral * 408/647-6112 * ...!uunet!drivax!braun * braun@dri.com
Whoever is calm and sensible
is insane
-- Rumi
frank@croton.nyo.dec.com (Frank Wortner) (04/15/91)
In article <V4K1Y3Z@dri.com>, braun@dri.com (Kral) writes: > Can someone tell me if this is a known bug ... It seems that either csh > or awk is barfing on the '#!' majik number. Everything is working as documented. Here's a quote from the execve(2) manual page: An interpreter file begins with a line of the form ``#! inter- preter''. When an interpreter file is executed the system exe- cutes the specified interpreter, giving it the name of the origi- nally executed file as an argument, shifting over the rest of the original arguments. So, if we take your example: #! /bin/awk { print "This is a test." } # and place it in the file test.awk, here is what happens: The kernel gets an exec-something-or-other system call with test.awk as an argument. The loader figures out that this is an interpreter file. The call is rearranged so that it looks like this: /bin/awk test.awk Awk assumes that its first and only argument is a program. The words "test.awk" do not constitute a valid awk program. OOPS! Syntax error! If you want awk to execute your program try making one small change: #! /bin/awk -f instead of #! /bin/awk This way, when the loader calls /bin/awk, the result will be: /bin/awk -f test.awk and things will work the way you expect. Hope this clears things up a bit. Have fun! Frank