Arguments to a gawk script

Updated: October 28, 2024

Next, let's consider the gawk version, gawk_script, which looks like this:

#!/usr/bin/gawk -f
BEGIN {
        for (i = 0; i < ARGC; i++)
                print ARGV[i]
}

The -f argument is important; it tells gawk to read its script from the given file. Without -f, this script wouldn't work as expected.

If you run this script as ./gawk_script one two three, the loader invokes it as /usr/bin/gawk -f ./gawk_script one two three, and then gawk changes its full path to gawk. The output looks like this:

gawk
one
two
three
  翻译: