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: Davide Brini
Subject: Re: [bug-gawk] Passing Parameters to Gawk Executable Script
Date: Sat, 01 Mar 2014 10:56:52 +0100

> 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]