Re: Shebang - why are parameters not splitted on whitespace?

From: Geralt
Date: Wed Dec 03 2008 - 12:30:17 EST


On Wed, Dec 3, 2008 at 4:56 PM, Américo Wang <xiyou.wangcong@xxxxxxxxx> wrote:
> On Wed, Dec 3, 2008 at 3:14 PM, Geralt <usr.gentoo@xxxxxxxxxxxxxx> wrote:
>> Hi,
>>
>> I've just noticed, that it's not possible to use more than one
>> parameter in a shebang on linux, because everything following the
>> executable path in the shebang is treated as one parameter, so for
>> example
>> #!/bin/awk --re-interval -f
>> in a script called "test.awk" results in a call likes this:
>> /bin/awk "--re-interval -f" ./test.awk
>> when running it with "./test.awk".
>>
>> Is there any reason why the parameters are not split before passing
>> them on to the program?
>
>
> Hello,
>
> I think this behavior is different on different platforms, you can
> find some clues
> in man page of execve(2):
>
> The semantics of the optional-arg argument of an interpreter script
> vary across implementations. On Linux, the entire string following the
> interpreter name is passed as a single argument to the interpreter, and
> this string can include white space. However, behavior differs on some
> other systems. Some systems use the first white space to terminate
> optional-arg. On some systems, an interpreter script can have multiple
> arguments, and white spaces in optional-arg are used to delimit the
> arguments
>
> It seems that POSIX doesn't specify this.
>
> Thanks.
>

Hello,

I should have anticipated this objection :-). I'm aware that this is
not consistent among Unix operating systems (you can find more about
it here [1]), but I was specifically refering to linux in this case
and why it handles the shebang arguments as one big string and not as
single arguments for the application.



Geralt.


[1] http://www.in-ulm.de/~mascheck/various/shebang/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/