From owner-freebsd-current@FreeBSD.ORG Sat Oct 2 18:59:27 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 2869B16A4CE for ; Sat, 2 Oct 2004 18:59:27 +0000 (GMT) Received: from smtp4.server.rpi.edu (smtp4.server.rpi.edu [128.113.2.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id B267943D41 for ; Sat, 2 Oct 2004 18:59:26 +0000 (GMT) (envelope-from drosih@rpi.edu) Received: from [128.113.24.47] (gilead.netel.rpi.edu [128.113.24.47]) by smtp4.server.rpi.edu (8.13.0/8.13.0) with ESMTP id i92IxOcw017161; Sat, 2 Oct 2004 14:59:25 -0400 Mime-Version: 1.0 X-Sender: drosih@mail.rpi.edu Message-Id: In-Reply-To: <20041002052856.GE17792@nexus.dglawrence.com> References: <200410020349.i923nG8v021675@northstar.hetzel.org> <20041002052856.GE17792@nexus.dglawrence.com> Date: Sat, 2 Oct 2004 14:59:24 -0400 To: freebsd-current@freebsd.org From: Garance A Drosihn Cc: freebsd-current@freebsd.org Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-CanItPRO-Stream: default X-RPI-SA-Score: undef - spam-scanning disabled X-Scanned-By: CanIt (www . canit . ca) Subject: Re: Bug in #! processing (long reply) 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: Sat, 02 Oct 2004 18:59:27 -0000 At 10:28 PM -0700 10/1/04, David G. Lawrence wrote: > > The following patch changes the check for end of line, so that > > a comment on the first line must be preceded by white space > > (' ' or '\t'). > > Personally, I'm thinking that all of the support for a "comment" >on the interpreter line is bogus and it would be better to back out >rev 1.21 rather than add even more complicated code to work around >all of the problems that it causes. From some quick testing, it seems that # is not recognized as a comment on Solaris, aix or recent redhat WS. So I think we would be better off not supporting it. The way to support the documented feature is on a per-shell basis. The command interpreter is passing the remaining arguments to the shell it is calling, so any shell could decide that it will treat "# " as a comment. That means the behavior of "#" will depend on which shell is being called, but then the behavior of everything ELSE on that line is also determined by the shell being called, so I don't see why comments should be a special-case. The original change was based on http://www.FreeBSD.org/cgi/query-pr.cgi?pr=16393 Which starts out by saying: Basically, if I follow the suggestions in the perl book to make portably executable scripts, I must use a shebang hack where the perl script starts being executed as a sh script. sh will pass it off to perl. Currently sh chokes on the # after -- as the executable. I use this feature of perl myself, it is very useful in some circumstances. There is one important detail though -- the fix which was committed is wrong on how the feature works. The PR gives the example of: #!/bin/sh -- # -*- perl -*- eval "exec perl $0 -S ${1+'$@'}" if 0; print "1+1=", (1+1), "\n"; First off, the above example script does not actually work on linux (or at least not on Redhat WS 3.0). Second, when it works on solaris or aix, it works because of how /bin/sh processes the rest of the line. It is not because the command-interpreter has stripped off everything after the '#'. If you remove the '--' on the above example, it fails immediately on aix and solaris. In fact, it seems to be the '--' which is causing the rest of the line to be ignored, not the '#'. The PR is correct in that this feature is documented by perl books, but the right way to support the feature is to change /bin/sh and not the command interpreter. The PR includes a followup reply from Ahmon Dancy with some additional proof that the change to the command interpreter was the wrong way to fix this. Since this perl feature is documented in many places (including the famous "Camel" book from O'Reilly), we can not just drop the support in the command interpreter. But if we first fix /bin/sh then I believe we can drop it. -- Garance Alistair Drosehn = gad@gilead.netel.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu