# Some questions about Ruby and it's environment

**URL:** <https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986>\
**Category:** ruby-talk\
**Created:** [15 July 2006 01:55 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986 "2006-07-15T01:55:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Just\_Another\_Victim2](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Just\_Another\_Victim2](https://rubytalk.org/u/Just_Another_Victim2)\
**Post date:** [15 July 2006 01:55 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/1 "2006-07-15T01:55:09Z")

</div>

I have two issues in Ruby which are bugging me.

&nbsp;&nbsp;&nbsp;&nbsp;On my (MS Windows) system, I have a couple of programs to help me live  
my electronic life and some of them are written in Ruby (are they still  
called "programs" or are they "scripts?"). I keep all these programs in a  
directory and have an execution path to them.  
&nbsp;&nbsp;&nbsp;&nbsp;I also have some patterns that come up time and time again in my Ruby  
code so I have factored them out into their own files so I may "require"  
them in any of my Ruby scripts.  
&nbsp;&nbsp;&nbsp;&nbsp;The problem is that Ruby can't find them. I had hoped that Ruby would  
search for "required" files in the directory of the running script but this  
doesn't appear to be the case. I could have used the magic "$0" variable  
but then I'd have to operate on it before using it. I also considered  
refactoring this work and using that but...  
&nbsp;&nbsp;&nbsp;&nbsp;Is there anything I can do to get Ruby to find these "required" scripts?

&nbsp;&nbsp;&nbsp;&nbsp;My second issue is not very serious but a curiosity to me. I used to  
use PERL so some of my useful "programs" are still written in that language.  
I tried to call a PERL script from a Ruby script and that myseriously  
failed. I did a search on groups.google and found that you need to call the  
PERL interpreter, directly. I found this a little odd since PERL scripts  
have no problem calling other PERL scripts. It's not a problem of the  
environment, since Ruby can call executables in the execution path.  
&nbsp;&nbsp;&nbsp;&nbsp;So, what's up with that? Why isn't the Ruby interpreter like PERL in  
this respect?

&nbsp;&nbsp;&nbsp;&nbsp;Thank you for your help!

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [15 July 2006 03:05 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/2 "2006-07-15T03:05:37Z")

</div>

> On my (MS Windows) system, I have a couple of programs to help me live my electronic life and some of them are written in Ruby (are they still called "programs" or are they "scripts?"). I keep all these programs in a directory and have an execution path to them.
> 
> I also have some patterns that come up time and time again in my Ruby code so I have factored them out into their own files so I may "require" them in any of my Ruby scripts.

Are those files in ruby's load path?

> The problem is that Ruby can't find them. I had hoped that Ruby would search for "required" files in the directory of the running script but this doesn't appear to be the case.

Ruby does not.

> I could have used the magic "$0" variable but then I'd have to operate on it before using it. I also considered refactoring this work and using that but...
> 
> Is there anything I can do to get Ruby to find these "required" scripts?

Ruby searches these paths:

ruby -e 'p $LOAD\_PATH'

You can use the -I argument or the RUBYLIB environment variable to add paths to this. You can also put your extra libraries in your site\_ruby directory.

> I tried to call a PERL script from a Ruby script and that myseriously  
> failed. I did a search on groups.google and found that you need to call the PERL interpreter, directly. I found this a little odd since PERL scripts have no problem calling other PERL scripts. It's not a problem of the environment, since Ruby can call executables in the execution path.

I don't believe you. Please show us an error.

$ cat x.pl  
#!/usr/bin/env perl

print "hi\n";

$ ruby -e 'system "./x.pl"'  
hi

> **···**
>
> On Jul 14, 2006, at 6:55 PM, Just Another Victim of the Ambient Morality wrote:
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Collins\_Justin](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@Collins\_Justin](https://rubytalk.org/u/Collins_Justin)\
**Post date:** [15 July 2006 05:39 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/3 "2006-07-15T05:39:51Z")

</div>

Eric Hodel wrote:

> > On my (MS Windows) system, I have a couple of programs to help me live my electronic life and some of them are written in Ruby (are they still called "programs" or are they "scripts?"). I keep all these programs in a directory and have an execution path to them.
> > 
> > I also have some patterns that come up time and time again in my Ruby code so I have factored them out into their own files so I may "require" them in any of my Ruby scripts.
> 
> Are those files in ruby's load path?
> 
> > The problem is that Ruby can't find them. I had hoped that Ruby would search for "required" files in the directory of the running script but this doesn't appear to be the case.
> 
> Ruby does not.

Well, it does look in the directory from which the script is run, which is not necessarily where the script is located.

> > I could have used the magic "$0" variable but then I'd have to operate on it before using it. I also considered refactoring this work and using that but...
> > 
> > Is there anything I can do to get Ruby to find these "required" scripts?
> 
> Ruby searches these paths:
> 
> ruby -e 'p $LOAD\_PATH'

And the directory the scripts is started in shows up in that array as '.'

> You can use the -I argument or the RUBYLIB environment variable to add paths to this. You can also put your extra libraries in your site\_ruby directory.
> 
> > I tried to call a PERL script from a Ruby script and that myseriously  
> > failed. I did a search on groups.google and found that you need to call the PERL interpreter, directly. I found this a little odd since PERL scripts have no problem calling other PERL scripts. It's not a problem of the environment, since Ruby can call executables in the execution path.
> 
> I don't believe you. Please show us an error.
> 
> $ cat x.pl  
> #!/usr/bin/env perl
> 
> print "hi\n";
> 
> $ ruby -e 'system "./x.pl"'  
> hi

This is on Windows...maybe that makes a difference in this case? I don't know that Windows respects the #!  
(I have no idea, I don't do any programming in Windows)

-Justin

> **···**
>
> > On Jul 14, 2006, at 6:55 PM, Just Another Victim of the Ambient \> Morality wrote:

---

<div class="post-metadata">

**Author:** ![Just\_Another\_Victim2](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Just\_Another\_Victim2](https://rubytalk.org/u/Just_Another_Victim2)\
**Post date:** [15 July 2006 05:41 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/4 "2006-07-15T05:41:46Z")

</div>

"Eric Hodel" \<drbrain@segment7.net\> wrote in message  
news:D50A04D4-B38E-433D-8C47-38AC2E67C079@segment7.net...

> > Is there anything I can do to get Ruby to find these "required" scripts?
> 
> Ruby searches these paths:
> 
> ruby -e 'p $LOAD\_PATH'
> 
> You can use the -I argument or the RUBYLIB environment variable to add  
> paths to this. You can also put your extra libraries in your site\_ruby  
> directory.

&nbsp;&nbsp;&nbsp;&nbsp;Thanks, I went with the environment variable. It's what I was looking  
for...

> > I tried to call a PERL script from a Ruby script and that myseriously  
> > failed. I did a search on groups.google and found that you need to call  
> > the PERL interpreter, directly. I found this a little odd since PERL  
> > scripts have no problem calling other PERL scripts. It's not a problem  
> > of the environment, since Ruby can call executables in the execution  
> > path.
> 
> I don't believe you. Please show us an error.
> 
> $ cat x.pl  
> #!/usr/bin/env perl
> 
> print "hi\n";
> 
> $ ruby -e 'system "./x.pl"'  
> hi

&nbsp;&nbsp;&nbsp;&nbsp;Interestingly enough, I remember seeing this on the other post in this  
newsgroup. This is what this scenario looks like for me:

$cat x.pl  
print "hi\n"

$ruby -e 'puts `x.pl`'  
-e:1:in ``': Exec format error - x.pl (Errno::ENOEXEC)  
&nbsp;&nbsp;&nbsp;&nbsp;from -e:1

&nbsp;&nbsp;&nbsp;&nbsp;Of course, in DOS, the command line uses the "\>" symbol but I didn't  
want to create any confusion with quoted text. Of course, the solution was  
to use the "system" method but, really, what's so different with the  
familiar `` operator? ...Yet you didn't know this nor did you use it in  
your example. This suggests to me that you don't use this operator anymore.  
Why not? The "system" call doesn't even return the output of the command  
nor does this output actually reach stdout...

> **···**
>
> > On Jul 14, 2006, at 6:55 PM, Just Another Victim of the Ambient Morality \> wrote:

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [15 July 2006 07:41 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/5 "2006-07-15T07:41:34Z")

</div>

> "Eric Hodel" \<drbrain@segment7.net\> wrote in message  
> news:D50A04D4-B38E-433D-8C47-38AC2E67C079@segment7.net...
> 
> > > I tried to call a PERL script from a Ruby script and that myseriously  
> > > failed. I did a search on groups.google and found that you need to call  
> > > the PERL interpreter, directly. I found this a little odd since PERL  
> > > scripts have no problem calling other PERL scripts. It's not a problem  
> > > of the environment, since Ruby can call executables in the execution  
> > > path.
> > 
> > I don't believe you. Please show us an error.
> > 
> > $ cat x.pl  
> > #!/usr/bin/env perl
> > 
> > print "hi\n";
> > 
> > $ ruby -e 'system "./x.pl"'  
> > hi
> 
> Interestingly enough, I remember seeing this on the other post in this newsgroup. This is what this scenario looks like for me:
> 
> $cat x.pl  
> print "hi\n"
> 
> $ruby -e 'puts `x.pl`'  
> -e:1:in ``': Exec format error - x.pl (Errno::ENOEXEC)  
> &nbsp;&nbsp;&nbsp;&nbsp;from -e:1
> 
> Of course, in DOS, the command line uses the "\>" symbol but I didn't want to create any confusion with quoted text. Of course, the solution was to use the "system" method but, really, what's so different with the familiar `` operator?

Are you sure it worked with system?

try:

$ ruby -e 'p system("./x.pl")'

You should see a hi and a true printed, something like this:

hi  
true

The differences between ` and system shouldn't be important for getting this to work, I think Windows needs to know how to run .pl files for this to work.

> ...Yet you didn't know this nor did you use it in your example. This suggests to me that you don't use this operator anymore. Why not?

I could have used `, but chose not to. I use ` when I need to capture stdout.

> The "system" call doesn't even return the output of the command nor does this output actually reach stdout...

Well, it may not be running at all and returning false.

Do you have Windows mapping the perl interpreter to .pl files? What happens when you double-click a .pl file from explorer?

A Windows expert may need to help you on this problem. Ruby just asks the OS to run these things, so if the OS can't figure out what to do with it Ruby won't be able to either. ☹

> **···**
>
> On Jul 14, 2006, at 10:41 PM, Just Another Victim of the Ambient Morality wrote:
> 
> > > On Jul 14, 2006, at 6:55 PM, Just Another Victim of the Ambient \>\> Morality wrote:
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Just\_Another\_Victim2](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Just\_Another\_Victim2](https://rubytalk.org/u/Just_Another_Victim2)\
**Post date:** [15 July 2006 21:10 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/6 "2006-07-15T21:10:05Z")

</div>

"Justin Collins" \<collinsj@seattleu.edu\> wrote in message  
news:44B881BE.2090807@seattleu.edu...

> This is on Windows...maybe that makes a difference in this case? I don't  
> know that Windows respects the #!  
> (I have no idea, I don't do any programming in Windows)

&nbsp;&nbsp;&nbsp;&nbsp;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...

&nbsp;&nbsp;&nbsp;&nbsp;The Windows command line certainly knows how to execute scripts (via  
"file associations" based on the extension) so I think it's up to Ruby to  
take advantage of this information, if possible...

---

<div class="post-metadata">

**Author:** ![Just\_Another\_Victim2](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Just\_Another\_Victim2](https://rubytalk.org/u/Just_Another_Victim2)\
**Post date:** [15 July 2006 21:05 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/7 "2006-07-15T21:05:16Z")

</div>

"Eric Hodel" \<drbrain@segment7.net\> wrote in message  
news:9379782E-03F1-4272-91BD-A6725FB78988@segment7.net...

> > Of course, in DOS, the command line uses the "\>" symbol but I didn't  
> > want to create any confusion with quoted text. Of course, the solution  
> > was to use the "system" method but, really, what's so different with the  
> > familiar `` operator?
> 
> Are you sure it worked with system?
> 
> try:
> 
> $ ruby -e 'p system("./x.pl")'
> 
> You should see a hi and a true printed, something like this:
> 
> hi  
> true
> 
> The differences between ` and system shouldn't be important for getting  
> this to work, I think Windows needs to know how to run .pl files for this  
> to work.

&nbsp;&nbsp;&nbsp;&nbsp;Ah, indeed, system didn't work. Windows does know how to execute PERL  
files so this behaviour is curious...

> > ...Yet you didn't know this nor did you use it in your example. This  
> > suggests to me that you don't use this operator anymore. Why not?
> 
> I could have used `, but chose not to. I use ` when I need to capture  
> stdout.

&nbsp;&nbsp;&nbsp;&nbsp;Is it faster not to capture output if you don't need it?

> > The "system" call doesn't even return the output of the command nor does  
> > this output actually reach stdout...
> 
> Well, it may not be running at all and returning false.

&nbsp;&nbsp;&nbsp;&nbsp;This is, in fact, the case. The following works:

ruby -e 'system "perl x.pl"'

&nbsp;&nbsp;&nbsp;&nbsp;...which, again, shows that Ruby (or Windows) can search execution paths  
for things to execute. It seems clear that something, somewhere, is having  
trouble associating .pl files to the PERL interpreter. Indeed, simply  
executing "x" (without the extension) on the command line doesn't work, so  
this might show evidence of that. However, if x were a ruby script,  
executing that on the command line \_would\_ work! Yet, it won't if passed to  
the "system" method, even if we were to add the extension. So, something is  
quite different between the command line and the Ruby "system" method...

> Do you have Windows mapping the perl interpreter to .pl files? What  
> happens when you double-click a .pl file from explorer?

&nbsp;&nbsp;&nbsp;&nbsp;It launches a DOS command window with the script executing...

> A Windows expert may need to help you on this problem. Ruby just asks  
> the OS to run these things, so if the OS can't figure out what to do with  
> it Ruby won't be able to either. ☹

&nbsp;&nbsp;&nbsp;&nbsp;I think you may be right. This looks like it's either a peculiarity of  
MS Windows or of the Win32 implementation of Ruby...  
&nbsp;&nbsp;&nbsp;&nbsp;Thanks for your input!

> **···**
>
> > On Jul 14, 2006, at 10:41 PM, Just Another Victim of the Ambient Morality \> wrote:

---

<div class="post-metadata">

**Author:** ![John\_W\_Kennedy](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@John\_W\_Kennedy](https://rubytalk.org/u/John_W_Kennedy)\
**Post date:** [15 July 2006 22:35 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/8 "2006-07-15T22:35:09Z")

</div>

Just Another Victim of the Ambient Morality wrote:

> &nbsp;&nbsp;&nbsp;&nbsp;I'm pretty sure the "#!" line is meaningless on Windows and the shell doesn't even bother looking for it.

The shell doesn't. (However, Apache, when running under Windows, does, just to freak out newbies, I half-suspect.)

> **···**
>
> --  
> John W. Kennedy  
> "The blind rulers of Logres  
> Nourished the land on a fallacy of rational virtue."  
> &nbsp;&nbsp;&nbsp;-- Charles Williams. "Taliessin through Logres: Prelude"

---

<div class="post-metadata">

**Author:** ![N\_Okia](https://avatars.discourse-cdn.com/v4/letter/n/fbc32d/32.png) [@N\_Okia](https://rubytalk.org/u/N_Okia)\
**Post date:** [15 July 2006 23:30 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/9 "2006-07-15T23:30:11Z")

</div>

Just Another Victim of the Ambient Morality wrote:

> &nbsp;&nbsp;&nbsp;&nbsp;The Windows command line certainly knows how to execute scripts (via  
> "file associations" based on the extension) so I think it's up to Ruby to  
> take advantage of this information, if possible...

However, the .rb file extension is associated with Rocket eBook Reader.  
So anything that expects this extension to always work in Windows can  
run into odd results.

Another reason why file extension is a cruddy indicator of file  
metadata, but that's the legacy we have from DOS...

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [15 July 2006 23:53 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/10 "2006-07-15T23:53:34Z")

</div>

I believe you want system("start x.pl") or system("start blah.rb")

> **···**
>
> On Jul 15, 2006, at 5:10 PM, Just Another Victim of the Ambient Morality wrote:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;The Windows command line certainly knows how to execute scripts (via  
> > "file associations" based on the extension) so I think it's up to Ruby to  
> > take advantage of this information, if possible...

---

<div class="post-metadata">

**Author:** ![Scheming\_Commie](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@Scheming\_Commie](https://rubytalk.org/u/Scheming_Commie)\
**Post date:** [2 August 2006 03:15 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/11 "2006-08-02T03:15:10Z")

</div>

#!/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.

> **···**
>
> On Sat, 15 Jul 2006 21:06:25 +0000, Just Another Victim of the Ambient Morality wrote:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;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...

---

<div class="post-metadata">

**Author:** ![James\_Britt3](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@James\_Britt3](https://rubytalk.org/u/James_Britt3)\
**Post date:** [15 July 2006 23:16 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/12 "2006-07-15T23:16:29Z")

</div>

John W. Kennedy wrote:

> Just Another Victim of the Ambient Morality wrote:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;I'm pretty sure the "#!" line is meaningless on Windows and the shell doesn't even bother looking for it.
> 
> The shell doesn't. (However, Apache, when running under Windows, does, just to freak out newbies, I half-suspect.)

But it's configurable if you want Apache to use the Windows-associated application to execute CGI scripts.

> **···**
>
> --  
> James Britt
> 
> "Discover the recipes you are using and abandon them."  
> &nbsp;&nbsp;- Brian Eno and Peter Schmidt, Oblique Strategies

---

<div class="post-metadata">

**Author:** ![Brian\_Palmer2](https://avatars.discourse-cdn.com/v4/letter/b/dbc845/32.png) [@Brian\_Palmer2](https://rubytalk.org/u/Brian_Palmer2)\
**Post date:** [2 August 2006 04:14 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/13 "2006-08-02T04:14:09Z")

</div>

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

> **···**
>
> 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:
> > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;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.

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [2 August 2006 18:57 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/14 "2006-08-02T18:57:19Z")

</div>

cron does not set PATH, so scripts with this #! won't work.

> **···**
>
> On Aug 1, 2006, at 8:15 PM, Scheming Commie wrote:
> 
> > On Sat, 15 Jul 2006 21:06:25 +0000, Just Another Victim of the Ambient \> Morality wrote:
> > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;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.
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Michal\_hramrach\_Such](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Michal\_hramrach\_Such](https://rubytalk.org/u/Michal_hramrach_Such)\
**Post date:** [8 August 2006 23:15 UTC](https://rubytalk.org/t/some-questions-about-ruby-and-its-environment/28986/15 "2006-08-08T23:15:22Z")

</div>

however, on some platforms /usr/bin/env is broken. Not to mention the  
occasions when there are several interpreters installed.

Thanks

Michal

> **···**
>
> On 8/2/06, Scheming Commie \<ired@timecube.com\> 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.
