I don't know if this a bug or not but I get a syntax error when when
trying to pass ARGC[Argind] to zerofile. gawk version: 4.0.2 OS: Ubuntu 12.4
#!/usr/bin/gawk -f
# All known awk implementations silently skip over zero-length files.
This is a by-product of awk's implicit
# read-a-record-and-match-against-the-rules loop:
# when awk tries to read a record from an empty file, it immediately
receives an end of file
# indication, closes the file, and proceeds on to the next command-line
data file, WITHOUT executing any
# user-level awk program code.
# Using gawk's ARGIND variable , it is possible to detect when an empty
data file
# has been skipped.
# zerofile.awk --- library file to process empty input files
BEGIN { Argind = 0 }
ARGIND > Argind + 1 {
v = ARGV[Argind]
for (Argind++; Argind < ARGIND; Argind++)
zerofile(a, Argind) # get syntax error for ARGV[Argind]
}
ARGIND != Argind { Argind = ARGIND }
END {
d = ARGV[Argind]
if (ARGIND > Argind)
for (Argind++; Argind <= ARGIND; Argind++)
zerofile(d, Argind)
}
my zerofile function
#!/usr/bin/gawk -f
function zerofile(a, Argind )
{
print ARGIND,Argind, ARGV[Argind]
}
I wrote this to understand how the post increment operator took effect
on the parameters