[comp.unix.shell] #!/usr/bin/nawk -f

cmf851@anu.oz.au (Albert Langer) (05/27/91)

I always assumed it was "standard unix" for an executable file with
a first line as above to have "#!" recognized as a "magic number"
that causes execve(2) when called by sh to execute a command, to
use the $PATH variable to get a full path {filename} for the command
then actually call /usr/bin/nawk -f {filename} (or whatever the word
following #! and the single paramater following that is).

It works for me on SunOs 4.1 but the script always get interpreted
as an ordinary sh script instead of an awk script, whether I put
a space after #! or not, when I try on ISC 386ix 2.0.2. There does
not seem to be a man page for execve on ISC that I can find, and
the man page for exec(2) does not refer to anything except
ordinary shell scripts in this context (thus conforming to the
behaviour I am actually seeing, so apparently it's a "feature"
not a "bug" :-)

Is there some way to get the behaviour I was expecting on ISC
386ix?

Also, I have had trouble using:

nawk '
... lots of awk script ...
' awkparamaters
continue shell script

Even without awkparamaters I get "too many paramaters" or some
such as an error message. What am I doing wrong?

Anyway, that doesn't worry me so much as I prefer to keep the
awk scripts in separate *.awk files anyway, but I want the
shell script to find the awkfile when it is in the $PATH
if I use:

nawk -f $awkfile

I don't want to have to specify a directory but only a basename.

The work-around I am planning to use is:

nawk -f `findpath $awkfile`

Where findpath contains:

#! /bin/sh
set - `type $1`;echo $3

Is there some better way to fix this?

P.S. I would appreciate it if any suggestions could be emailed
direct to the address in .sig file below so I get beeped at
with the happy news while I am still working away at a mess
of awk scripts and NOT reading news. (Also I don't normally
read comp.unix.shell but am cross-posting there in case it
is not a 386ix problem.)

Will summarize here if anyone asks.

P.P.S. Is there some other newsgroup I should be asking in?

--
Opinions disclaimed (Authoritative answer from opinion server)
Header reply address wrong. Use cmf851@csc2.anu.edu.au