Re: Bug in #! processing

From: Ceri Davies <ceri_at_submonkey.net>
Date: Wed, 29 Sep 2004 14:11:37 +0100
On Wed, Sep 29, 2004 at 01:47:06PM +0200, S?awek ?ak wrote:
> 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.

You're actually guessing though, right?  I can't find this in the
standard; if you know it's there then I'd appreciate a reference.

> > (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.

Yes.

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

Are you guessing again?

I believe that the FreeBSD behaviour is closer to "correct" than
anything else we're seeing in this thread.  I should be able to specify

	#!/usr/bin/perl -w -0

or whatever without having everything other than the first argument
ignored.

>     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

Linux 2.4.20 does this too.

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

That seems wrong too.  #! shouldn't be magic anywhere other than at the
beginning of a file.

>     I don't see any explanation for current
>     behavior therefore I'm reporting it.

The explanation is that we only process that line up to a '#' or
newline.  Backing out revision 1.21 of sys/kern/imgact_shell.c is one
fix, or perhaps allowing a '#' character to be escaped.  I'm not sure if
I see an overwhelming reason for either.

Ceri
-- 
It is not tinfoil, it is my new skin.  I am a robot.

Received on Wed Sep 29 2004 - 11:11:39 UTC

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