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.
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
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
Alle Thursday 25 September 2008, Zouplaz ha scritto:
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:
On Thursday 25 September 2008 07:50 am, Lex W. wrote:
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.: //foo
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 all for you help, now the script files are executed the right way
!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.