The shebang line in a Unix script is supposed to specify a full path, so this:
#!/usr/local/bin/ruby
is valid but this is not:
#!ruby
The problem with the first form is that, well, you need to use a full path but the actual path won't be the same on all systems. The env
utility is often used to allow a script to search the PATH
environment variable for the appropriate interpreter, env
should always be in /usr/bin/env
so you can safely use that as a full path and then let env
search the PATH
for the named interpreter.
From the fine manual:
env [-i] [name=value]... [utility [argument...]]
The env utility shall obtain the current environment, modify it according to its arguments, then invoke the utility named by the utility operand with the modified environment.
That isn't terribly helpful in your case but I figured I should include it anyway. The shebang use of env
is a bit of a hack that doesn't use the intended behavior of env
.