#!/usr/bin/env

Tom Metro blu at vl.com
Mon Jan 30 15:19:16 EST 2006


Ed Hill wrote:
> By executing the script using "/usr/bin/env INTERPRETER", it will choose
> the first instance of INTERPRETER that it finds in your PATH.

OK, so env(1) isn't directly providing any functionality here, other 
than providing a convenient way of calling execlp(3) (search the path 
for the executable and run it) as a side effect, and working around the 
limitation that:

#!INTERPRETER

(with no path) won't work on most platforms.


> So, for instance, if multiple versions of php are installed...
> then you can select which one you want:

I could see pros and cons to this. Updating bang paths is a pain, and 
usually minimized through symlinks. Depending on the search path could 
lead to surprises. If you happen have some version specific scripts 
dependent on /usr/bin/INTERPRETER and an admin installs an incompatible 
version in /usr/local/bin/INTERPRETER that happens to be first in your 
path, your scripts break. Once you discover the problem, you can of 
course adjust for it by changing your path or modifying the bangpath on 
those version specific scripts.


> The portability is just a fact.

What I wanted to know was what makes it portable. Apparently it is due 
to env(1) being ubiquitous and consistently having that path searching 
side effect in the various implementations.

  -Tom

-- 
Tom Metro
Venture Logic, Newton, MA, USA
"Enterprise solutions through open source."
Professional Profile: http://tmetro.venturelogic.com/



More information about the Discuss mailing list