45.3 Don't Need a Shell for Your Script? Don't Use OneIf your UNIX understands ( 44.4 ) files that start with:
#!
you don't have to use those lines to start a shell, such as First, here are two scripts. Both scripts print the second word from each line of text files. One uses a shell; the other runs awk directly:
% Let's run both commands and time ( 39.2 ) them:
% One of the things that's really important to understand here is that when the kernel runs the program on the interpreter line, it is given the script's filename as an argument. If the intepreter program understands a file directly, like /bin/sh does, nothing special needs to be done. But a program like awk or sed requires the -f option if it is to read its script from a file. This leads to the seemingly odd syntax in the example above, with a call to awk -f with no following filename. The script itself is the input file!
One implication of this usage is that the interpreter program needs
to understand - |
|