Bug in #! processing (long reply)

David G. Lawrence dg at dglawrence.com
Sat Oct 2 16:36:03 PDT 2004

> 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 <dancy at dancysoft.com> 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.

   Err, your terminology is a bit off (/bin/sh is the "command interpreter");
what we're talking about is the behavior of the execve() system call in the
kernel, specifically the imgact_shell image activation module. When the
system sees that a file needs to be interpreted by something (e.g. sh, perl,
python, or some other language interpreter) it parses the interpreter line
specified at the top of the file (#!/bin/sh) and sets up to invoke that with
the original file as the argument.
   ...but I see what you're saying and I agree with the thought. The
interpreter should decide if the # is a comment, not the kernel.


David G. Lawrence
Download Technologies, Inc. - http://www.downloadtech.com - (866) 399 8500
TeraSolutions, Inc. - http://www.terasolutions.com - (888) 346 7175
The FreeBSD Project - http://www.freebsd.org
Pave the road of life with opportunities.

More information about the freebsd-current mailing list