[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

env command

Christian Roese

2/2/2008 5:58:00 PM

[Note: parts of this message were removed to make it a legal post.]

Does anyone know why I can type this at the cmd line:

/usr/bin/env ruby -w

and get the correct functionality, but if I use this line in the shebang
line of my .rb files, I get an error from env stating that "ruby -w can't be
found"? If I change the line to use just ruby (without the -w option), it
works perfectly. I've seen plenty of programs scattered around the net that
use that same line in a shebang line so I know it should work.

Any help would be greatly appreciated!

--
Christian Roese

4 Answers

Daniel Brumbaugh Keeney

2/2/2008 7:14:00 PM

0

On Feb 2, 2008 11:57 AM, Christian Roese <croese@gmail.com> wrote:
> Does anyone know why I can type this at the cmd line:
>
> /usr/bin/env ruby -w
>
> and get the correct functionality, but if I use this line in the shebang
> line of my .rb files, I get an error from env stating that "ruby -w can't be
> found"? If I change the line to use just ruby (without the -w option), it
> works perfectly. I've seen plenty of programs scattered around the net that
> use that same line in a shebang line so I know it should work.
>
> Any help would be greatly appreciated!
>
> --
> Christian Roese

http://en.wikipedia.org/wik...(Unix)#Portability

Daniel Brumbaugh Keeney

Christian Roese

2/2/2008 9:25:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Feb 2, 2008 1:13 PM, Daniel Brumbaugh Keeney <devi.webmaster@gmail.com>
wrote:

> On Feb 2, 2008 11:57 AM, Christian Roese <croese@gmail.com> wrote:
> > Does anyone know why I can type this at the cmd line:
> >
> > /usr/bin/env ruby -w
> >
> > and get the correct functionality, but if I use this line in the shebang
> > line of my .rb files, I get an error from env stating that "ruby -w
> can't be
> > found"? If I change the line to use just ruby (without the -w option),
> it
> > works perfectly. I've seen plenty of programs scattered around the net
> that
> > use that same line in a shebang line so I know it should work.
> >
> > Any help would be greatly appreciated!
> >
> > --
> > Christian Roese
>
> http://en.wikipedia.org/wik...(Unix)#Portability<http://en.wikipedia.org/wik...%28Unix%29#Portability>
>
> Daniel Brumbaugh Keeney
>
>
Does this mean I'm hosed on my linux system and I'll have to use either

/usr/local/bin/ruby -w

or

/usr/bin/env ruby (without the -w switch)

in my programs? Is there any way to delimit these args so that env sees
them as 2 args instead of one whole string?

--
Christian Roese

Felix Windt

2/2/2008 10:14:00 PM

0

On Sun, 2008-02-03 at 06:25 +0900, Christian Roese wrote:
> On Feb 2, 2008 1:13 PM, Daniel Brumbaugh Keeney <devi.webmaster@gmail.com>
> wrote:
>
> > On Feb 2, 2008 11:57 AM, Christian Roese <croese@gmail.com> wrote:
> > > Does anyone know why I can type this at the cmd line:
> > >
> > > /usr/bin/env ruby -w
> > >
> > > and get the correct functionality, but if I use this line in the shebang
> > > line of my .rb files, I get an error from env stating that "ruby -w
> > can't be
> > > found"? If I change the line to use just ruby (without the -w option),
> > it
> > > works perfectly. I've seen plenty of programs scattered around the net
> > that
> > > use that same line in a shebang line so I know it should work.
> > >
> > > Any help would be greatly appreciated!
> > >
> > > --
> > > Christian Roese
> >
> > http://en.wikipedia.org/wik...(Unix)#Portability<http://en.wikipedia.org/wik...%28Unix%29#Portability>
> >
> > Daniel Brumbaugh Keeney
> >
> >
> Does this mean I'm hosed on my linux system and I'll have to use either
>
> /usr/local/bin/ruby -w
>
> or
>
> /usr/bin/env ruby (without the -w switch)
>
> in my programs? Is there any way to delimit these args so that env sees
> them as 2 args instead of one whole string?
>

In short, you're hosed in regards to that particular method.

Unless I'm mistaken, the shebang line is interpreted by the kernel, and
on Linux it only accepts one parameter to the interpreter the line
defines - so #!/usr/bin/env ruby -w will always call /usr/bin/env with
the parameter "ruby -w", which is not a valid command. There's no way
around this.

If, however, all you need this for is the -w switch to turn on warnings,
just don't do that with a switch to the ruby binary and use the $VERBOSE
global variable to turn warnings on and off. The manpage for ruby even
hints to this:

-w Enables verbose mode without printing version message at
the beginning. It sets the $VERBOSE variable to true.

That solution should be more portable.

HTH,

Felix


Christian Roese

2/2/2008 10:24:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Feb 2, 2008 4:13 PM, fw <fwmailinglists@gmail.com> wrote:

> On Sun, 2008-02-03 at 06:25 +0900, Christian Roese wrote:
> > On Feb 2, 2008 1:13 PM, Daniel Brumbaugh Keeney <
> devi.webmaster@gmail.com>
> > wrote:
> >
> > > On Feb 2, 2008 11:57 AM, Christian Roese <croese@gmail.com> wrote:
> > > > Does anyone know why I can type this at the cmd line:
> > > >
> > > > /usr/bin/env ruby -w
> > > >
> > > > and get the correct functionality, but if I use this line in the
> shebang
> > > > line of my .rb files, I get an error from env stating that "ruby -w
> > > can't be
> > > > found"? If I change the line to use just ruby (without the -w
> option),
> > > it
> > > > works perfectly. I've seen plenty of programs scattered around the
> net
> > > that
> > > > use that same line in a shebang line so I know it should work.
> > > >
> > > > Any help would be greatly appreciated!
> > > >
> > > > --
> > > > Christian Roese
> > >
> > > http://en.wikipedia.org/wik...(Unix)#Portability<http://en.wikipedia.org/wik...%28Unix%29#Portability>
> <http://en.wikipedia.org/wik...%28Unix%29#Portability>
> > >
> > > Daniel Brumbaugh Keeney
> > >
> > >
> > Does this mean I'm hosed on my linux system and I'll have to use either
> >
> > /usr/local/bin/ruby -w
> >
> > or
> >
> > /usr/bin/env ruby (without the -w switch)
> >
> > in my programs? Is there any way to delimit these args so that env sees
> > them as 2 args instead of one whole string?
> >
>
> In short, you're hosed in regards to that particular method.
>
> Unless I'm mistaken, the shebang line is interpreted by the kernel, and
> on Linux it only accepts one parameter to the interpreter the line
> defines - so #!/usr/bin/env ruby -w will always call /usr/bin/env with
> the parameter "ruby -w", which is not a valid command. There's no way
> around this.
>
> If, however, all you need this for is the -w switch to turn on warnings,
> just don't do that with a switch to the ruby binary and use the $VERBOSE
> global variable to turn warnings on and off. The manpage for ruby even
> hints to this:
>
> -w Enables verbose mode without printing version message at
> the beginning. It sets the $VERBOSE variable to true.
>
> That solution should be more portable.
>
> HTH,
>
> Felix
>
>
>
Nice, I was searching for something like that $VERBOSE variable (much akin
to perl's 'use warnings' capability) and I completely missed that part of
the man page. Thanks

--
Christian Roese