env question

  • Thread starter Brian Schröder
  • Start date
B

Brian Schröder

Hello Group,

This is maybe not exactly a ruby question, but maybe you have also
thought about this.

I like to use
#!/usr/bin/env ruby
as a shebang line. On the other hand, I also like calling ruby with -w

I can't get env to call ruby with arguments. Things that are not working:
#!/usr/bin/env ruby -w
#!/usr/bin/env 'ruby -w'

Could anyone help me on this one?

regards,


Brian
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: env question"

|On 05.10.2004, at 12:04, Brian Schröder wrote:
|> Could anyone help me on this one?
|
|#!/usr/bin/env ruby
|$VERBOSE = true

If you don't need compile-time check.

matz.
 
R

Robert Klemme

Yukihiro Matsumoto said:
Hi,

In message "Re: env question"
|On 05.10.2004, at 12:04, Brian Schröder wrote:
|> Could anyone help me on this one?
|
|#!/usr/bin/env ruby
|$VERBOSE = true

If you don't need compile-time check.

Personally I don't understand why pople use the "#!/usr/bin/env ruby"
idiom anyway. AFAIK using the real path to the ruby interpreter is a)
more efficient and b) more secure. So why use env? Did I miss something?

Kind regards

robert
 
A

Ara.T.Howard

Personally I don't understand why pople use the "#!/usr/bin/env ruby" idiom
anyway. AFAIK using the real path to the ruby interpreter is a) more
efficient and b) more secure. So why use env? Did I miss something?

many of my scripts are run from 30-40 machines. some of the machines mount a
central nfs server on which i've installed ruby and all required packages for
my software. however, as an optimization and to improve nfs failure tolerance
many of our machine cache a lot of software (including ruby) and data files
further up the path than the nfs ruby. finally, a third class of machines has
the system ruby only (1.6.8). if i write a script and use

#!/usr/bin/env ruby

the system finds the 'right' ruby at run time. without this i'd have to
maintain many copies of my scripts. this problem extends to the situation
where i give you a ruby script and don't know where your ruby is, and to
upgrading ruby (i have 1.8.1 before 1.8.2 in our group path because i'm
migrating to 1.8.2, but reverse this for testing). env helps with all of this
and, yes, it's probably less secure - but so is anything that involves getting
alot of work done quickly ;-)

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================
 
R

Robert Klemme

many of my scripts are run from 30-40 machines. some of the machines mount a
central nfs server on which i've installed ruby and all required packages for
my software. however, as an optimization and to improve nfs failure tolerance
many of our machine cache a lot of software (including ruby) and data files
further up the path than the nfs ruby. finally, a third class of machines has
the system ruby only (1.6.8). if i write a script and use

#!/usr/bin/env ruby

the system finds the 'right' ruby at run time. without this i'd have to
maintain many copies of my scripts. this problem extends to the situation
where i give you a ruby script and don't know where your ruby is, and to
upgrading ruby (i have 1.8.1 before 1.8.2 in our group path because i'm
migrating to 1.8.2, but reverse this for testing). env helps with all of this
and, yes, it's probably less secure - but so is anything that involves getting
alot of work done quickly ;-)

Sure enough. But what's the advantage over

#!ruby

Are there shells that don't allow this? Does env search not only $PATH
but elsewhere?

Kind regards

robert
 
A

Ara.T.Howard

Sure enough. But what's the advantage over

#!ruby

Are there shells that don't allow this?


jib:~ > for shell in tcsh csh sh bash ksh;do echo $shell; $shell -c ./a.rb;done
tcsh
./a.rb: Command not found.
csh
./a.rb: Command not found.
sh
sh: ./a.rb: ruby: bad interpreter: No such file or directory
bash
bash: ./a.rb: ruby: bad interpreter: No such file or directory
ksh
ksh: ./a.rb: No such file or directory

does that work for you - if so what os/shell?

Does env search not only $PATH but elsewhere?

AFAIK it searches only in $PATH.

cheers.


-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================
 
R

Robert Klemme

jib:~ > for shell in tcsh csh sh bash ksh;do echo $shell; $shell -c ../a.rb;done
tcsh
./a.rb: Command not found.
csh
./a.rb: Command not found.
sh
sh: ./a.rb: ruby: bad interpreter: No such file or directory
bash
bash: ./a.rb: ruby: bad interpreter: No such file or directory
ksh
ksh: ./a.rb: No such file or directory

does that work for you - if so what os/shell?

17:46:28 [ruby]: for sh in `cat /etc/shells` ; do echo $sh; $sh -c ./a.rb;
done
/bin/sh
yes!
/bin/bash
yes!
/bin/ksh
yes!
/bin/pdksh
yes!
/bin/tcsh
yes!
/bin/zsh
yes!
/usr/bin/sh
yes!
/usr/bin/bash
yes!
/usr/bin/ksh
yes!
/usr/bin/pdksh
yes!
/usr/bin/tcsh
yes!
/usr/bin/zsh
yes!
17:46:48 [ruby]: cat ./a.rb
#!ruby
puts "yes!"
17:46:56 [ruby]: uname -a
CYGWIN_NT-5.0 bond 1.5.10(0.116/4/2) 2004-05-25 22:07 i686 unknown unknown
Cygwin

I'll check on my debian when I'm at home.
AFAIK it searches only in $PATH.

Ok, that's what I thought.

Kind regards

robert
 
M

Michael Campbell

17:46:28 [ruby]: for sh in `cat /etc/shells` ; do echo $sh; $sh -c ./a.rb;
done
/bin/sh
yes!

..


Robert, you're EXPLICITLY running each shell; that's different from
what Ara did; he was having the shell parse the #! line. If you go
with "$sh -c rubyscript", you don't need the #! at all, which makes
the question moot, no?
 
R

Robert Klemme

Michael Campbell said:
17:46:28 [ruby]: for sh in `cat /etc/shells` ; do echo $sh; $sh -c ../a.rb;
done
/bin/sh
yes!

.


Robert, you're EXPLICITLY running each shell; that's different from
what Ara did; he was having the shell parse the #! line. If you go
with "$sh -c rubyscript", you don't need the #! at all, which makes
the question moot, no?

Each shell is run individually but it evaluates the first line of the
script; the test is quite the same as Ara's. Please read the code again
carefully.

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top