I sometimes use the technique of passing in data via the command line in
the place normally reserved for filename args. Yes, I realize this is
non-standard, and that there are other ways to do it. I'm not interested
in any arguments or suggestions about those alternatives. The technique is
something like:
$ someCommand | gawk 'BEGIN { ARGC = 1 }
/something/ { for (i in ARGV) print i,ARGV[i] }' 'string 1' 'string 2' ...
The trick here is that you explicitly set ARGC to 1, so that your strings
don't get interpreted as filenames. Written as above, it all works fine.
As long as you "kill" ARGV via setting ARGC in the BEGIN clause, it works
as expected.
Now, just for fun, I was playing around with some alternatives, and found
that neither of the following variations work (and by "not work", I mean
that it tries to interpret "string 1" as a filename, which of course fails
and causes a fatal error abort from the program.
1) $ someCommand | gawk -v ARGC=1 '
/something/ { for (i in ARGV) print i,ARGV[i] }' 'string 1' 'string 2' ...
2) $ someCommand | gawk '
/something/ { for (i in ARGV) print i,ARGV[i] }' ARGC=1 'string 1' 'string 2' ...
I'm curious as to why neither of these work. To my mind, it seems they should.
(Particularly, the first one; I can sort of get why the second one might
not work)
--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Pedantic