Go to the first, previous, next, last section, table of contents.


Executable @command{awk} Programs

Once you have learned @command{awk}, you may want to write self-contained @command{awk} scripts, using the `#!' script mechanism. You can do this on many Unix systems(7) as well as on the GNU system. For example, you could update the file `advice' to look like this:

#! /bin/awk -f

BEGIN { print "Don't Panic!" }

After making this file executable (with the @command{chmod} utility), simply type `advice' at the shell and the system arranges to run @command{awk}(8) program. The rest of the argument list is either options to @command{awk}, or data files, or both.} as if you had typed `awk -f advice':

$ chmod +x advice
$ advice
-| Don't Panic!

Self-contained @command{awk} scripts are useful when you want to write a program that users can invoke without their having to know that the program is written in @command{awk}.

Advanced Notes: Portability Issues with `#!'

Some systems limit the length of the interpreter name to 32 characters. Often, this can be dealt with by using a symbolic link.

You should not put more than one argument on the `#!' line after the path to @command{awk}. It does not work. The operating system treats the rest of the line as a single argument and passes it to @command{awk}. Doing this leads to confusing behavior--most likely a usage diagnostic of some sort from @command{awk}.

Finally, the value of ARGV[0] (see section Built-in Variables) varies depending upon your operating system. Some systems put `awk' there, some put the full pathname of @command{awk} (such as `/bin/awk'), and some put the name of your script (`advice'). Don't rely on the value of ARGV[0] to provide your script name.


Go to the first, previous, next, last section, table of contents.