In the documentation in the URL you posted it says that the tmpdir stuff
is in the file tmpdir.rb, so you should try
#!/usr/bin/env ruby
require 'tmpdir'
Thank you very much as always!!
Why the line is needed - ` #!/usr/bin/env ruby` ? I have seen lots of
code having that line at top. I am not aware of that one.
Could you help me ?
The #! line (shebang line) specifies which interpreter to use. So a script starting with
#!/usr/bin/ruby
would always use the /usr/bin/ruby interpreter to run the script.
As I use chruby to let myself switch between ruby scripts the ruby I want to run for my programs is pointed at by /Users/mike/.rbenv/shims/ruby, whose directory is on my PATH. When I start a script with
#!/usr/bin/env ruby
then the env program searches my PATH for the first ruby it finds and uses that to interpret the script. This is useful to me as it lets me easily switch versions in my shell and have the ruby version I'm interested in execute the script.
It also helps when distributing a script for use on systems where you don't know if ruby is /bin/ruby, /usr/local/bin/ruby, /usr/bin/ruby, or something else - as long as the PATH is set up correctly ruby will be found.
There is a downside to /usr/bin/env in that it depends on the path of the user running it, so the same script on a system run by two different users can use different interpreters. That can cause confusion when debugging.
Hope this helps,
Mike
···
On 2013-06-22, at 12:27 PM, Love U Ruby <lists@ruby-forum.com> wrote:
The #! line (shebang line) specifies which interpreter to use. So a
script starting with
#!/usr/bin/ruby
would always use the /usr/bin/ruby interpreter to run the script.
Good explanation..
So suppose I am having Ruby 1.9.3-p374, Ruby2.0.0-p0 are installed. Now
is the line `#!/usr/bin/ruby` would also be able to the desired version
as I want ? If no then how can I run the same script with different
version of Ruby(s)?
ratdog:tmp mike$ ls -l try.rb
-rwxr-xr-x 1 mike mike 71 22 Jun 14:02 try.rb
ratdog:tmp mike$ cat try.rb
#!/usr/bin/env ruby
puts "I'm running under #{RUBY_VERSION}"
__END__
ratdog:tmp mike$ rbenv version
2.0.0-p195 (set by /Users/mike/.rbenv/version)
ratdog:tmp mike$ ./try.rb
I'm running under 2.0.0
ratdog:tmp mike$ rbenv shell 1.9.3-p429
ratdog:tmp mike$ rbenv version
1.9.3-p429 (set by RBENV_VERSION environment variable)
ratdog:tmp mike$ ./try.rb
I'm running under 1.9.3
So the same script runs under different interpreters depending on which version I have set to execute using rbenv.
Hope this helps,
Mike
···
On 2013-06-22, at 1:19 PM, Love U Ruby <lists@ruby-forum.com> wrote:
Mike Stok wrote in post #1113281:
The #! line (shebang line) specifies which interpreter to use. So a
script starting with
#!/usr/bin/ruby
would always use the /usr/bin/ruby interpreter to run the script.
Good explanation..
So suppose I am having Ruby 1.9.3-p374, Ruby2.0.0-p0 are installed. Now
is the line `#!/usr/bin/ruby` would also be able to the desired version
as I want ? If no then how can I run the same script with different
version of Ruby(s)?