From: Brian Palmer Date: 2006-08-02T13:14:09+09:00 Subject: Re: How to auto-locate interpreter image On Aug 1, 2006, at 9:15 PM, Scheming Commie wrote: > On Sat, 15 Jul 2006 21:06:25 +0000, Just Another Victim of the Ambient > Morality wrote: >> I'm pretty sure the "#!" line is meaningless on Windows and >> the shell >> doesn't even bother looking for it. Indeed, it always struck me a >> little >> weird that every script knows exactly where the interpreter image >> is. What >> if it were to move? All your scripts will suddenly break! An >> annoying, >> albeit, unlikely scenario... > > #!/usr/bin/env perl > #!/usr/bin/env ruby > .. etc > > env finds the interpreter wherever it is and runs it, as you'd expect. > > A neat trick, I don't know why it isn't used, well, universally. > > Of course it relies on env being in /usr/bin but, that changes less > (never) than where particular interpreters are. > > When you use a line like #!/usr/bin/env ruby, env searches each directory on your path for a program called ruby -- but in some situations, such as running under a web server like Apache or from a remote ssh session, your path isn't set, or is set to a restricted subset of your normal path, so /usr/bin/env won't find what it's looking for. As I understand it, that's why it's not more universally used. For instance, on the web hosting service I often use Apache doesn't set any path at all, so while /usr/bin/env exists, it can't be used in this way. -- Brian