NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: /usr/bin/env behaviour?

On Sun 09 Nov 2008 at 11:03:20 +1100, Malcolm Herbert wrote:
> Thinking about it, it may not even be env's fault if /bin/sh (or
> whatever is responsible for parsing the #! line) is giving env a badly
> tokenised set of arguments ...

Here you're closest. It is the execve() system call that parses the line
and decides to invoke env. Unfortunately it allows only a single

EXECVE(2)                 NetBSD System Calls Manual                 EXECVE(2)
     execve() transforms the calling process into a new process.  The new
     process is constructed from an ordinary file, whose name is pointed to by
     path, called the new process file.  This file is either an executable
     object file, or a file of data for an interpreter.  [...]

     An interpreter file begins with a line of the form:

           #! interpreter [arg]

     When an interpreter file is execve()d the system runs the specified
     interpreter.  If the optional arg is specified, it becomes the first
     argument to the interpreter, and the name of the originally execve()d
     file becomes the second argument; otherwise, the name of the originally
     execve()d file becomes the first argument.  The original arguments are
     shifted over to become the subsequent arguments.  The zeroth argument,
     normally the name of the execve()d file, is left unchanged.  The inter-
     preter named by interpreter must not itself be an interpreter file.  (See
     script(7) for a detailed discussion of interpreter file execution.)

> Regards,
> Malcolm
___ Olaf 'Rhialto' Seibert    -- You author it, and I'll reader it.
\X/ rhialto/at/      -- Cetero censeo "authored" delendum esse.

Home | Main Index | Thread Index | Old Index