Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Sep 2004 14:11:37 +0100
From:      Ceri Davies <ceri@submonkey.net>
To:        S?awek ?ak <zaks@prioris.mini.pw.edu.pl>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Bug in #! processing
Message-ID:  <20040929131136.GA2493@submonkey.net>
In-Reply-To: <86k6ud2t6t.fsf@thirst.unx.era.pl>
References:  <861xgm5ltz.fsf@thirst.unx.era.pl> <20040928194853.GT2493@submonkey.net> <86k6ud2t6t.fsf@thirst.unx.era.pl>

next in thread | previous in thread | raw e-mail | index | archive | help

--yWPvFVzSs/idg2A5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Sep 29, 2004 at 01:47:06PM +0200, S?awek ?ak wrote:
> Ceri Davies <ceri@submonkey.net> writes:
>=20
> > On Tue, Sep 28, 2004 at 07:45:28PM +0200, S?awek ?ak wrote:
> >> Hi,
> >>=20
> >>     It seems that there is a long standing bug in processing of comman=
d-line
> >>     options for scripts and such. Take following files:
> >>=20
>=20
> [...]
>=20
>=20
> >>     On FreeBSD 5.x:
> >>    =20
> >> thirst<zaks>(1790)% ./tst.sh
> >> Main.c test
> >> ./main
> >> -
> >> ./tst.sh
> >>=20
> >>     On Solaris:
> >>=20
> >> sb8:root> ./tst.sh
> >> Main.c test
> >> ./main
> >> -#!
> >> ./tst.sh
> >>=20
> >> 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=20
>    =20
>     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
>=20
>     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
>=20
>     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:
>=20
> #!./main 1 2 3 -#!
> print ok
>=20
>     You get:
>=20
> 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.
>=20
>     The behavior I'd like to have, and which seems correct is not botheri=
ng with
>     second, 3rd and so on occurence of #! in the first line of script. Fe=
asible?
>     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
--=20
It is not tinfoil, it is my new skin.  I am a robot.

--yWPvFVzSs/idg2A5
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)

iD8DBQFBWrSIocfcwTS3JF8RAqT0AJ9Yw0hJby+VyTsIsoJGR2oCuRn+YACgt8OD
1hiNXqBUnlAB9NNSCxBIFlQ=
=qWWH
-----END PGP SIGNATURE-----

--yWPvFVzSs/idg2A5--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040929131136.GA2493>