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 04:51:30 -0800 (PST)

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.


On Saturday, March 1, 2014 4:56 AM, Davide Brini <address@hidden> wrote:
> From: Mitchell Pryor
>
> This may not be a bug, but it seems like one to me.
>
> Script:
>
>
> #!/bin/gawk -v num=$1 -f
> BEGIN {
>     print "num=" num
> }
>
> When I try to execute this script as follows why does it say that 'num' is an illegal variable?
>
> ./myscript <some-number> <some-text-file>
>
> Is '-f' the only allowable switch for gawk within an executable format?  I can't find any documentation addressing this specific situation.
>
>
> Thanks for any help you can give.

This has nothing to do with awk but rather with the way your OS parses the !# line. Short answer is, you're on a system that takes everything following the first word as a single argument. Linux behave this way.

Long answer here: http://www.in-ulm.de/~mascheck/various/shebang/ , the table at the bottom lists the behavior of different operating systems.

Note that even if the system parsed the individual arguments, I'm not sure the script would work the way you want anyway, due to the $1 substitution.



reply via email to

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