bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Passing Parameters to Gawk Executable Script


From: Mitchell Pryor
Subject: Re: [bug-gawk] Passing Parameters to Gawk Executable Script
Date: Sat, 1 Mar 2014 06:15:26 -0800 (PST)

I did not notice the leading space before the string 'num' in the error message. That sounds illegal.  But if the string '-v num=$1  -f' is seen by awk as a single single argument, what did it do with '-v'.  It seems to be attempting to parse this string argument into pieces, but not doing so intelligently.  It would have been more useful, if it had just rejected the entire string and displayed it in the error message.

Well, I appreciate your attempts to educate me.  I understand what my options are regarding passing parameters to an executable script and how to handle them.  I guess I'll do some more experimenting.



On Saturday, March 1, 2014 8:12 AM, Davide Brini <address@hidden> wrote:
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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]