[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: awk progfile



> What's happening?

1) $ awk '/Date/' respaldo
Runs awk with the program-text "/Date/" on the input-file respaldo. This
program is only a pattern. The default action is to print the entire line of
the input-file to the screen if the pattern matches.

2) $ cat respchk
   /Date/ respaldo
   $ awk -f respchk
This runs awk with the program-file respchk but without an input-file. The
respchk program-file consists of the pattern "/Date/ respaldo". respaldo is
interpreted as a variable here and because it's empty (by default), it
doesn't have an effect on the program. As there is no input-file specified,
awk 'hangs', that is, waits for input from stdin. 

A program-file for the awk statement in 1) would only consist of "/Date/"
and you would specify the input-file on the command line:
3) $ cat respchk
   /Date/
   $ awk -f respchk respaldo

With the "#!" line, assuming the path "/usr/bin/awk" is valid ($ which awk)
and respchk is executable ($ chmod +x respchk), this would look like
4) $ cat respchk
   #! /usr/bin/awk -f
   /Date/
   $ ./respchk respaldo
respchk is now the program and respaldo is the input-file again. 

Hope this helps.

BTW: Can somebody give me a clue why awk is /usr/bin/awk in Debian (also
e.g., ksh) (and /bin/awk in most other systems I've seen)?
What's the standard "#! " way to get a script running on both? ln -s
/usr/bin/<prg> /bin/<prg> in Debian (and vice versa in other systems)?
(please cc me)

Andreas


Reply to: