Awk location: #!/bin/awk -f versus #!/usr/bin/awk

Awk location: #!/bin/awk -f versus #!/usr/bin/awk

Post by Hai V » Thu, 30 Oct 2008 02:50:36

I am developing some AWK scripts, as usual, my first line is:
#!/bin/awk -f

This works on Linux system, bun on my Mac OS X 10.5 (Leopard), it
should be:
#!/usr/bin/awk -f

Is there a way to create a script which works independently of where
AWK is? Thanks.

Awk location: #!/bin/awk -f versus #!/usr/bin/awk

Post by Janis Papa » Thu, 30 Oct 2008 03:00:48

Often there's a link in Unix systems from the one directory to the
other, but you're not guaranteed it to be there. If you have admin
access to the system(s) you can create the link. Otherwise you are
always free to explicitly call the awk interpreter (with the path
implicitly defined through the PATH definition), i.e., instead of
making the script executable and calling it, say, as

yourscript.awk yourdatafiles...

call it always as

awk -f yourscript.awk yourdatafiles...