On Sat, 1 Mar 2014 04:51:30 -0800 (PST), Mitchell Pryor
<
address@hidden> wrote:
> Thanks for your response. I'm running this script in Fedora 17 Linux, by
> the way. I understand that the operating system is involved in this
> process, but I'm not sure why you would say awk has nothing to do with
> it. If ARGC says there are 3 arguments passed to the script does that
> not indicate that the operating system invoked awk and passed 3
> arguments? Also, awk (gawk) is "seeing" the 'num' variable, but
> labelling it not 'legal'. I would think an awk developer would have some
> idea why this would happen. But I guess I'm destined to continue my
> journey in the dark. Thanks again.
That's the problem, ARGC is *NOT* 3. In fact there's no ARGC at all at the
time awk fails.
Basically the system is running your script as if it were invoked as:
awk '-v num=$1 -f' yourcode
(single quotes to pack everything into a single argument; try it and see,
"yourcode" can be anything).
Awk bails out while still parsing its command line
(as built by the system
out of the #! line).
It doesn't even get to the point where actual awk code would be run (and
thus concepts like ARGC etc. would start to make sense).
Look at the error message closely:
awk: fatal: ` num' is not a legal variable name
See, it tries to interpret " num" (with a leading space) as a variable
name. It's the command line parser that fails; the awk code in the script
does not matter.
--
D.