Env question

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

···

--
Brian Schröder
http://ruby.brian-schroeder.de/

#!/usr/bin/env ruby
$VERBOSE = true

Florian Frank

···

On 05.10.2004, at 12:04, Brian Schröder wrote:

Could anyone help me on this one?

Hi,

···

In message "Re: env question" on Tue, 5 Oct 2004 19:25:16 +0900, Florian Frank <flori@nixe.ping.de> writes:

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.

"Yukihiro Matsumoto" <matz@ruby-lang.org> schrieb im Newsbeitrag
news:1096981307.926461.11274.nullmailer@x31.priv.netlab.jp...

Hi,

>> 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

···

In message "Re: env question" > on Tue, 5 Oct 2004 19:25:16 +0900, Florian Frank <flori@nixe.ping.de> writes:
>On 05.10.2004, at 12:04, Brian Schröder wrote:

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 :wink:

-a

···

On Tue, 5 Oct 2004, Robert Klemme wrote:

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?

--

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

===============================================================================

<Ara.T.Howard@noaa.gov> schrieb im Newsbeitrag
news:Pine.LNX.4.60.0410050756510.7297@harp.ngdc.noaa.gov...

> 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 :wink:

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

···

On Tue, 5 Oct 2004, Robert Klemme wrote:

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

···

On Tue, 5 Oct 2004, Robert Klemme wrote:
--

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

===============================================================================

<Ara.T.Howard@noaa.gov> schrieb im Newsbeitrag
news:Pine.LNX.4.60.0410050843500.7297@harp.ngdc.noaa.gov...

> 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?

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.

> Does env search not only $PATH but elsewhere?

AFAIK it searches only in $PATH.

Ok, that's what I thought.

Kind regards

    robert

···

On Tue, 5 Oct 2004, Robert Klemme wrote:

..

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?

···

On Wed, 6 Oct 2004 00:49:55 +0900, Robert Klemme <bob.news@gmx.net> wrote:

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

"Michael Campbell" <michael.campbell@gmail.com> schrieb im Newsbeitrag
news:811f2f1c041005105466eefc5b@mail.gmail.com...

> 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

···

On Wed, 6 Oct 2004 00:49:55 +0900, Robert Klemme <bob.news@gmx.net> wrote: