bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Additional parameters in a #! line throwing unexpected er


From: Davide Brini
Subject: Re: [bug-gawk] Additional parameters in a #! line throwing unexpected error
Date: Sun, 22 Dec 2013 12:37:32 +0100

On Sat, 21 Dec 2013 15:15:53 -0600, Tim Chase <address@hidden>
wrote:

> While this works:
> 
>   #!/usr/bin/awk -f
>   BEGIN {FS="."}
>   {print $1}
> 
> the following doesn't
> 
>   #!/usr/bin/awk -F. -f
>   {print $1}
> 
> failing with the following message:
> 
>   bash$ echo "hello.world" | ./demo.awk
>   awk: cmd. line:1: ./demo.awk
>   awk: cmd. line:1: ^ syntax error
>   awk: cmd. line:1: ./demo.awk
>   awk: cmd. line:1:   ^ unterminated regexp
> 
> It gives the same results if I put an extra space between the "-F"
> and the desired separator.  Also, using /usr/bin/awk
> vs. /usr/bin/gawk makes no difference.
> 
> The same code works as expected when it's all on the command-line:
> 
>   bash$ echo "hello.world" | awk -F. '{print $1}'
>   hello
> 
> According to the man/info pages, the syntax should allow for options
> before the "-f", and at least short options appear to be permissible
> within the #! line according to "Additionally, each long option has a
> corresponding short option, so that the option's functionality may be
> used from within #! executable scripts."
> 
> I don't seen any mention in the man/info pages as to why this
> wouldn't work.  Is this a documentation bug or a functionality bug?

In short, this has nothing to do with awk but rather with how your OS
parses the #! line.

The long answer is at 

http://www.in-ulm.de/~mascheck/various/shebang/

long but well worth the read.

tl;dr is "A very few systems deliver only the first argument, some systems
split up the arguments like a shell to fill up argv[], most system deliver
all arguments as a single string." Linux belongs to the latter category.

-- 
D.



reply via email to

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