Stefano Crocco
9/25/2008 11:52:00 AM
Alle Thursday 25 September 2008, Zouplaz ha scritto:
> Hello, this is not really related to the core language by itself but I
> don't remember how to have the interpreter launched when typing foo.rb
> or foo (if foo is the name of the script) under bash ?
>
> I remember that I have to put something like
> #! /usr/ruby
>
> at the beginnin of the script but I don't remember the right syntax and
> didn't found a Google way to express it.
>
>
>
> Thanks
You're almost there. It's #! followed by a space then the path of the ruby
executable:
#! /usr/bin/ruby
Another option is this:
#! /usr/bin/env ruby
This way, you don't need to know the position of the ruby executable, but only
of the env executable (which, I suppose, should be more standard). The
downside is that, at least with bash, you can't pass options to ruby. For
example, the line
#! /usr/bin/env ruby -w
tries to get from env the path of the program ruby -w. Since ruby -w is not a
program, you get an error.
In the first way, instead, you can pass options to ruby:
#! /usr/bin/ruby -w
Stefano