Invocation of ruby interpreter for .rb files under bash

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

the first line should be

#!/usr/bin/ruby

or wherever your script is.

Next, you have to mark the script as beeing executable .

chmod +x foo.rb

Note that since the first line of your script is #!/usr/bin/ruby ( or
wherever your ruby binary is located ) , the script's name doesn't have
to end with .rb.
After that , you can just write :
./foo

···

--
Posted via http://www.ruby-forum.com/.

Zouplaz wrote:

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

#!/usr/bin/ruby

to check the path please use: which ruby
on my box it returned /usr/bin/ruby
$ which ruby
/usr/bin/ruby

Regards

···

--
Posted via http://www.ruby-forum.com/\.

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

You should put the following line at the beginning of the script:
#!/usr/bin/env ruby

Then, you should make your script executable using the chmod command:
Prefacechmod +x foo.rb

Now, you should be able to run the script by typing:
./foo.rb

Regards,
Yaser Sulaiman

···

On Thu, Sep 25, 2008 at 2:44 PM, Zouplaz <user@domain.invalid> wrote:

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

Thanks all for you help, now the script files are executed the right way !

···

le 25/09/2008 13:42, Zouplaz nous a dit:

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.

the first line should be
#!/usr/bin/ruby
or wherever your script is.

^ s/script/ruby interpreter/

Next, you have to mark the script as beeing executable .

chmod +x foo.rb

Note that since the first line of your script is #!/usr/bin/ruby ( or
wherever your ruby binary is located ) , the script's name doesn't

have

to end with .rb.

After that , you can just write :
./foo

... assuming (I know) you are "in" the directory where the script is.

Alternatively, you can:

   * put the script in a directory on the path that Linux searches for
executables (then just type foo) (run =set | grep PATH=)
   * change the path which Linux searches for executables to include the
path where your script is located (again, run =set | grep PATH=)
   * include the full path to the executable on the command line,
e.g.: /<whatever>/foo

(Just feeling pedantic, I guess.)

Randy Kramer

···

On Thursday 25 September 2008 07:50 am, Lex Williams wrote:
--
I didn't have time to write a short letter, so I created a video
instead.--with apologies to Cicero, et.al.