Note that there are some explanatory texts on larger screens.

plurals
  1. PO/usr/bin/env questions regarding shebang line pecularities
    text
    copied!<p><strong>Questions</strong>:</p> <ul> <li>What does the kernel do if you stick a shell-script into the shebang line? </li> <li>How does the Kernel know which interpreter to launch?</li> </ul> <p><strong>Explanation</strong>:</p> <p>I recently wanted to write a wrapper around <em>/usr/bin/env</em> because my CGI Environment does not allow me to set the <em>PATH</em> variable, except globally (which of course sucks!).</p> <p>So I thought, "OK. Let's set PREPENDPATH and set <em>PATH</em> in a wrapper around env.". The resulting script (here called <em>env.1</em>) looked like this:</p> <pre><code>#!/bin/bash /usr/bin/env PATH=$PREPENDPATH:$PATH $* </code></pre> <p>which looks like it should work. I checked how they both react, after setting PREPENDPATH:</p> <pre><code>$ which /usr/bin/env python /usr/bin/env /usr/bin/python $ which /usr/bin/env.1 python /usr/bin/env /home/pi/prepend/bin/python </code></pre> <p>Look absolutely <em>perfect</em>! So far, so good. But look what happens to "Hello World!".</p> <pre><code># Shebang is #!/usr/bin/env python $ test-env.py Hello World! # Shebang is #!/usr/bin/env.1 python $ test-env.1.py Warning: unknown mime-type for "Hello World!" -- using "application/*" Error: no such file "Hello World!" </code></pre> <p>I guess I am missing something pretty fundamental about UNIX.</p> <p>I'm pretty lost, even after looking at the source code of the original <em>env</em>. It sets the environment and launches the program (or so it seems to me...).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload