DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Using awk

Command-line arguments

The command-line arguments are available to an awk program: the array ARGV contains the elements ARGV[0], ..., ARGV[ARGC-1]; as in C, ARGC is the count. ARGV[0] is the name of the program (generally awk); the remaining arguments are whatever was provided (excluding the program and any optional arguments).

The following command line (typed at the shell prompt) contains an awk program that echoes the arguments that appear after the program name:

   awk '
   BEGIN {
      for (i = 1; i < ARGC; i++)
            printf "%s ", ARGV[i]
      printf "\n"
   }' $*
You can modify or add to the arguments; you can also alter ARGC. As each input file ends, awk treats the next non-null element of ARGV (up to the current value of ARGC-1) as the name of the next input file.

The one exception to the rule that an argument is a filename is that if it is of the following form, then the variable var is set to the value value as if by assignment:

var=value

If value is a string, no quotes are needed. Such an argument is not treated as a filename.


Next topic: Using awk with other commands and the shell
Previous topic: getline function

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003