Re: Bug in #! processing

From: Sławek Żak <zaks_at_prioris.mini.pw.edu.pl>
Date: Wed, 29 Sep 2004 13:47:06 +0200
Ceri Davies <ceri_at_submonkey.net> writes:

> On Tue, Sep 28, 2004 at 07:45:28PM +0200, S?awek ?ak wrote:
>> Hi,
>> 
>>     It seems that there is a long standing bug in processing of command-line
>>     options for scripts and such. Take following files:
>> 

[...]


>>     On FreeBSD 5.x:
>>     
>> thirst<zaks>(1790)% ./tst.sh
>> Main.c test
>> ./main
>> -
>> ./tst.sh
>> 
>>     On Solaris:
>> 
>> sb8:root> ./tst.sh
>> Main.c test
>> ./main
>> -#!
>> ./tst.sh
>> 
>> sb8:root> uname -a
>> SunOS sb8 5.8 Generic_108528-21 sun4u sparc SUNW,UltraAX-i2
>
> [snip Tru64 and AIX]
>
>>     Any takers?
>
> It's easy enough to fix this case, but Solaris looks buggy in other
> areas 
    
    You should speel buggy as 'POSIX' in this case I guess.
    
> (I do not have any other systems to hand):
>
> 	FreeBSD 4.10-STABLE:
>
> $ cat tst.sh
> #!./main -f -o -#!
> print ok
> $ ./tst.sh
> Main.c test
> ./main
> -f
> -o
> -
> ./tst.sh

    Well, it is consistent with FreeBSD 5.x in this respect. Discards all after
    second #! when passing arguments to the interpretter.
    
> 	Solaris 9:
>
> $ ./tst.sh
> Main.c test
> ./main
> -f
> ./tst.sh

    This behavior is mandated by POSIX which, as I reckon, allows passing of
    only the first argument to the interpreter. It is confirmed by other
    supposedly compliant systems. I've checked before AIX 5.2, Solaris 8/9. Two
    raisins in the pie are Tru64 5.1B and HP-UX 11, which return some erm,
    strange results. For such script:

#!./main 1 2 3 -#!
print ok

    You get:

Main.c test
./main
1 2 3 -#!
./tst.sh

    Thus it seems that the systems squeeze all arguments in one and pass it that
    way to our handsome interpreter. Nevertheless both Tru64 and HPUX are
    dying and we got to move on with our lives.

    The behavior I'd like to have, and which seems correct is not bothering with
    second, 3rd and so on occurence of #! in the first line of script. Feasible?
    I guess so. The only commercial product on my systems uses -#! switch on all
    platforms as a script file mark. I don't see any explanation for current
    behavior therefore I'm reporting it.

/S    
    
Received on Wed Sep 29 2004 - 09:47:09 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:14 UTC