[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to find ruby?

Mark Probert

5/29/2005 11:06:00 PM


Hi ..

I am not sure of the best way of going about finding the location of Ruby for
a shebang line (*nix execution).

My scripts don't always have control of where Ruby might be installed (that is
the provenance of the destination organization's sysadmin). Some examples
that I have run across include

/usr/local/bin/ruby
/usr/bin/ruby
/opt/ruby1.8/bin/ruby
etc.

So, what do other people normally do when they have this kind of situation
when it comes to the shebang line? I'd rather do it in some generic manner
rather than have a substitution script run at install time (though that is an
option).

Thanks,

--
-mark. (probertm at acm dot org)


11 Answers

David Mitchell

5/29/2005 11:16:00 PM

0

I do this:

#!/usr/bin/env ruby

For an explanation of why this works, check:

man env

David

Mark Probert wrote:
> Hi ..
>
> I am not sure of the best way of going about finding the location of Ruby for
> a shebang line (*nix execution).
>
> My scripts don't always have control of where Ruby might be installed (that is
> the provenance of the destination organization's sysadmin). Some examples
> that I have run across include
>
> /usr/local/bin/ruby
> /usr/bin/ruby
> /opt/ruby1.8/bin/ruby
> etc.
>
> So, what do other people normally do when they have this kind of situation
> when it comes to the shebang line? I'd rather do it in some generic manner
> rather than have a substitution script run at install time (though that is an
> option).
>
> Thanks,
>


--
David Mitchell
Software Engineer
Telogis

NOTICE:
This message (including any attachments) contains CONFIDENTIAL
INFORMATION intended for a specific individual and purpose, and
is protected by law. If you are not the intended recipient,
you should delete this message and are hereby notified that any
disclosure, copying, or distribution of this message, or the
taking of any action based on it, is strictly prohibited.


Jim Menard

5/29/2005 11:17:00 PM

0

Mark Probert wrote:
> My scripts don't always have control of where Ruby might be installed (that is
> the provenance of the destination organization's sysadmin).

> So, what do other people normally do when they have this kind of situation
> when it comes to the shebang line? I'd rather do it in some generic manner
> rather than have a substitution script run at install time (though that is an
> option).

I use

#! /usr/bin/env ruby

The "env" command finds the ruby command on your path.

Jim
--
Jim Menard, jimm@io.com, http://www.io....
"I went on the Internet to find out how to prevent squirrel damage."
-- Betty March


nobu.nokada

5/29/2005 11:40:00 PM

0

Hi,

At Mon, 30 May 2005 08:05:40 +0900,
Mark Probert wrote in [ruby-talk:143962]:
> So, what do other people normally do when they have this kind of situation
> when it comes to the shebang line? I'd rather do it in some generic manner
> rather than have a substitution script run at install time (though that is an
> option).

$ cat a.rb
#!/bin/sh
exec ruby -x "$0" ${1+"$@"}
#! ruby -s
p $foo

$ ./a.rb -foo=123
"123"

But I feel the substitution is better. setup.rb [1] would do
it.

Note that all platforms might not have env under /usr/bin.

[1] http://raa.ruby-lang.org/pro...

--
Nobu Nakada


David Mitchell

5/30/2005 1:23:00 AM

0

>
> Note that all platforms might not have env under /usr/bin.
>

While it is true that some platforms might not have env in /usr/bin, a
bit of research turns up that all BSD distros have, almost all linux
distros do, and that basically covers 99.99% of the unix machines out
there (including OSX). While substitution will always work, sometimes
you may want a script that requires no installation, in which case using
env is your best bet.


--
David Mitchell
Software Engineer
Telogis

NOTICE:
This message (including any attachments) contains CONFIDENTIAL
INFORMATION intended for a specific individual and purpose, and
is protected by law. If you are not the intended recipient,
you should delete this message and are hereby notified that any
disclosure, copying, or distribution of this message, or the
taking of any action based on it, is strictly prohibited.


Eric Hodel

5/30/2005 4:30:00 AM

0

On 29 May 2005, at 16:40, nobu.nokada@softhome.net wrote:

> Hi,
>
> At Mon, 30 May 2005 08:05:40 +0900,
> Mark Probert wrote in [ruby-talk:143962]:
>
>> So, what do other people normally do when they have this kind of
>> situation
>> when it comes to the shebang line? I'd rather do it in some
>> generic manner
>> rather than have a substitution script run at install time (though
>> that is an
>> option).
>>
>
> $ cat a.rb
> #!/bin/sh
> exec ruby -x "$0" ${1+"$@"}
> #! ruby -s
> p $foo
>
> $ ./a.rb -foo=123
> "123"
>
> But I feel the substitution is better. setup.rb [1] would do
> it.
>
> Note that all platforms might not have env under /usr/bin.

Even more importantly, not every shell has the same path (cron).

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04



james_b

5/30/2005 4:56:00 AM

0

Eric Hodel wrote:
> Even more importantly, not every shell has the same path (cron).
>

Indeed. I've been bitten by this, so I now hard-code the specific Ruby
path into any code called by cron.

James


Jeremy Tregunna

5/30/2005 5:04:00 AM

0

On 29-May-05, at 7:05 PM, Mark Probert wrote:

>
> Hi ..
>
> I am not sure of the best way of going about finding the location of
> Ruby for
> a shebang line (*nix execution).
>
> My scripts don't always have control of where Ruby might be installed
> (that is
> the provenance of the destination organization's sysadmin). Some
> examples
> that I have run across include
>
> /usr/local/bin/ruby
> /usr/bin/ruby
> /opt/ruby1.8/bin/ruby
> etc.
>
> So, what do other people normally do when they have this kind of
> situation
> when it comes to the shebang line? I'd rather do it in some generic
> manner
> rather than have a substitution script run at install time (though
> that is an
> option).

Most modern shells will accept multiple arguments on a shebang line
(some older shells won't, but you shouldn't have a problem).

Use:

#!/path/to/env ruby

where /path/to/env is the location of env(1) (usually /usr/bin).

> -mark. (probertm at acm dot org)

--
Jeremy Tregunna
jtregunna@blurgle.ca




Nakada, Nobuyoshi

5/30/2005 7:07:00 AM

0

Hi,

At Mon, 30 May 2005 14:04:06 +0900,
Jeremy Tregunna wrote in [ruby-talk:143980]:
> Most modern shells will accept multiple arguments on a shebang line
> (some older shells won't, but you shouldn't have a problem).

It isn't a feature of shell, but of kernel, in common. A system
doesn't have it within kernel wouldn't be modern.

> Use:
>
> #!/path/to/env ruby

And a problem with this shebang line is you can't put any options to
ruby there (except for *BSD, perhaps).

--
Nobu Nakada


Brian Schröder

5/30/2005 7:45:00 AM

0

> [snip]
>
> NOTICE:
> This message (including any attachments) contains CONFIDENTIAL
> INFORMATION intended for a specific individual and purpose, and
> is protected by law. If you are not the intended recipient,
> you should delete this message and are hereby notified that any
> disclosure, copying, or distribution of this message, or the
> taking of any action based on it, is strictly prohibited.
>

I don't think you should post to a newsgroup using this footer. It
seems a bit contradictory to nail a confidential note onto a public
message board.

regards,

Brian

--
http://ruby.brian-sch...

Stringed instrument chords: http://chordlist.brian-sch...


Christian Neukirchen

5/30/2005 1:04:00 PM

0

Brian Schröder <ruby.brian@gmail.com> writes:

> From: Brian Schröder <ruby.brian@gmail.com>
> Subject: [OT Signature] Re: How to find ruby?
> To: ruby-talk@ruby-lang.org (ruby-talk ML)
> Date: Mon, 30 May 2005 16:45:00 +0900
> Reply-To: ruby-talk@ruby-lang.org
> X-Mail-Count: 143990
>
>> [snip]
>>
>> NOTICE:
>> This message (including any attachments) contains CONFIDENTIAL
>> INFORMATION intended for a specific individual and purpose, and
>> is protected by law. If you are not the intended recipient,
>> you should delete this message and are hereby notified that any
>> disclosure, copying, or distribution of this message, or the
>> taking of any action based on it, is strictly prohibited.
>>
>
> I don't think you should post to a newsgroup using this footer. It
> seems a bit contradictory to nail a confidential note onto a public
> message board.

Hey, you were not allowed to read that!

> regards,
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...