in reply to Modifying %ENV From The Shebang Line

I tried the first shebang line on my FreeBSD system, and it also failed. From looking at the truss output, it seems that the system uses execve(2) to call the shebang interpreter. So I looked at the execve manpage and found this paragraph:

     An interpreter file begins with a line of the form:

           #! interpreter arg

     When an interpreter file is execve'd, the system actually execve's 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 argu-
     ments are shifted over to become the subsequent arguments.  The zeroth
     argument is set to the specified interpreter.

Note: it's arg (singular). The manpage claims that this is POSIX standard, so it might apply to Linux, too.
  • Comment on Re: Modifying %ENV From The Shebang Line

Replies are listed 'Best First'.
Re^2: Modifying %ENV From The Shebang Line
by williams (Beadle) on Dec 17, 2007 at 23:28 UTC
    Maybe that explains some of the results I've seen, where it appears everything after interpreter is glommed into a single argument. I'm now left with attempts like the following, which just churn the CPU and never start Perl.
    #!/bin/bash eval 'LD_LIBRARY_PATH=/my/lib /usr/bin/perl /the/script' if $runningUnderSomeShell; warn "$ENV{LD_LIBRARY_PATH}\n";
    Again, this is based on perlrun, though I'm obviously doing something wrong.

    Thanks,

    Jim