From owner-freebsd-current@FreeBSD.ORG Wed Sep 29 13:11:39 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1516A16A4CE for ; Wed, 29 Sep 2004 13:11:39 +0000 (GMT) Received: from shrike.submonkey.net (cpc2-cdif3-6-0-cust204.cdif.cable.ntl.com [81.103.67.204]) by mx1.FreeBSD.org (Postfix) with ESMTP id 73F0143D55 for ; Wed, 29 Sep 2004 13:11:38 +0000 (GMT) (envelope-from setantae@submonkey.net) Received: from setantae by shrike.submonkey.net with local (Exim 4.42 (FreeBSD)) id 1CCeF7-000Gbn-2n; Wed, 29 Sep 2004 14:11:37 +0100 Date: Wed, 29 Sep 2004 14:11:37 +0100 From: Ceri Davies To: S?awek ?ak Message-ID: <20040929131136.GA2493@submonkey.net> Mail-Followup-To: Ceri Davies , S?awek ?ak , freebsd-current@freebsd.org References: <861xgm5ltz.fsf@thirst.unx.era.pl> <20040928194853.GT2493@submonkey.net> <86k6ud2t6t.fsf@thirst.unx.era.pl> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="yWPvFVzSs/idg2A5" Content-Disposition: inline In-Reply-To: <86k6ud2t6t.fsf@thirst.unx.era.pl> X-PGP: finger ceri@FreeBSD.org User-Agent: Mutt/1.5.6i Sender: Ceri Davies cc: freebsd-current@freebsd.org Subject: Re: Bug in #! processing X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Sep 2004 13:11:39 -0000 --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 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(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--