[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

proper usr/bin/env ruby shebang

Rob Sanheim

1/31/2007 4:45:00 PM

I'm trying to convert some bash scripts to use /usr/bin/env ruby
instead of hardcoded shebang lines, and running into an issue. Using
this:

#!/usr/bin/env ruby -w

results in this error:

/usr/bin/env: ruby -w: No such file or directory

If I remove the -w, it runs and works fine. But of course, I want
the warnings check in there...

This works fine from the command line:

rsanheim@seekingalpha06a [/sa/bin]$ /usr/bin/env ruby -w
FOO = "hi"
FOO = "bye"
-:2: warning: already initialized constant FOO

Any ideas? Forgive me if I'm missing something obvious here...This is
red hat 4, I believe...

thanks,
Rob

24 Answers

pat eyler

1/31/2007 4:56:00 PM

0

On 1/31/07, Rob Sanheim <rsanheim@gmail.com> wrote:
> I'm trying to convert some bash scripts to use /usr/bin/env ruby
> instead of hardcoded shebang lines, and running into an issue. Using
> this:
>
> #!/usr/bin/env ruby -w
>
> results in this error:
>
> /usr/bin/env: ruby -w: No such file or directory
>
> If I remove the -w, it runs and works fine. But of course, I want
> the warnings check in there...
>
> This works fine from the command line:
>
> rsanheim@seekingalpha06a [/sa/bin]$ /usr/bin/env ruby -w
> FOO = "hi"
> FOO = "bye"
> -:2: warning: already initialized constant FOO
>
> Any ideas? Forgive me if I'm missing something obvious here...This is
> red hat 4, I believe...

Either you're dating yourself, or you mean RHEL 4 ... (I still have
manuals from both RHL 3 and 4 (and maybe install media if I look
hard enough))


>
> thanks,
> Rob
>
>


--
thanks,
-pate
-------------------------
http://on-ruby.bl...

Rob Sanheim

1/31/2007 4:59:00 PM

0

On 1/31/07, pat eyler <pat.eyler@gmail.com> wrote:
> On 1/31/07, Rob Sanheim <rsanheim@gmail.com> wrote:
> > I'm trying to convert some bash scripts to use /usr/bin/env ruby
> > instead of hardcoded shebang lines, and running into an issue. Using
> > this:
> >
> > #!/usr/bin/env ruby -w
> >
> > results in this error:
> >
> > /usr/bin/env: ruby -w: No such file or directory
> >
> > If I remove the -w, it runs and works fine. But of course, I want
> > the warnings check in there...
> >
> > This works fine from the command line:
> >
> > rsanheim@seekingalpha06a [/sa/bin]$ /usr/bin/env ruby -w
> > FOO = "hi"
> > FOO = "bye"
> > -:2: warning: already initialized constant FOO
> >
> > Any ideas? Forgive me if I'm missing something obvious here...This is
> > red hat 4, I believe...
>
> Either you're dating yourself, or you mean RHEL 4 ... (I still have
> manuals from both RHL 3 and 4 (and maybe install media if I look
> hard enough))
>

You're right, I meant RHEL4.
- rob

Ara.T.Howard

1/31/2007 5:10:00 PM

0

Nobuyoshi Nakada

1/31/2007 5:13:00 PM

0

Hi,

At Thu, 1 Feb 2007 01:45:15 +0900,
Rob Sanheim wrote in [ruby-talk:237036]:
> I'm trying to convert some bash scripts to use /usr/bin/env ruby
> instead of hardcoded shebang lines, and running into an issue. Using
> this:
>
> #!/usr/bin/env ruby -w
>
> results in this error:
>
> /usr/bin/env: ruby -w: No such file or directory

Do not rely on /usr/bin/env, it may not exist.

#!/bin/sh
exec ruby -x "$0" "$@"
#!ruby -w

--
Nobu Nakada

Rob Sanheim

1/31/2007 5:18:00 PM

0

On 1/31/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> harp:~ > cat a.rb
> #!/usr/bin/env ruby -w
> p $VERBOSE
> FOO = 42 and FOO = 42
>
> harp:~ > ruby a.rb
> true
> a.rb:3: warning: already initialized constant FOO
>
> harp:~ > ruby -v
> ruby 1.8.4 (2005-12-01) [i686-linux]
>
> harp:~ > uname -srm
> Linux 2.4.21-47.0.1.EL i686
>
> harp:~ > cat /etc/redhat-release
> Red Hat Enterprise Linux WS release 3 (Taroon Update 8)
>
>
> what happens for you?
>
> -a
> --

Hmm, so that works -- the issue is where I run it as an executable
(see the end of the log)

sa [~]$ ruby a.rb
true
a.rb:3: warning: already initialized constant FOO

sa [~]$ ruby -v
ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-linux]

sa [~]$ uname -srm
Linux 2.6.9-42.0.3.ELsmp i686

sa [~]$ cat /etc/redhat-release
Red Hat Enterprise Linux ES release 4 (Nahant Update 4)

sa [~]$ chmod +x a.rb

sa [~]$ ./a.rb
/usr/bin/env: ruby -w: Permission denied

- Rob

Rob Sanheim

1/31/2007 5:21:00 PM

0

On 1/31/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
> Hi,
>
> At Thu, 1 Feb 2007 01:45:15 +0900,
> Rob Sanheim wrote in [ruby-talk:237036]:
> > I'm trying to convert some bash scripts to use /usr/bin/env ruby
> > instead of hardcoded shebang lines, and running into an issue. Using
> > this:
> >
> > #!/usr/bin/env ruby -w
> >
> > results in this error:
> >
> > /usr/bin/env: ruby -w: No such file or directory
>
> Do not rely on /usr/bin/env, it may not exist.
>
> #!/bin/sh
> exec ruby -x "$0" "$@"
> #!ruby -w
>

Ugh, so I need that at the top of all these scripts? I thought
/usr/bin/env was the 'better' way to go?

Kalman Noel

1/31/2007 5:25:00 PM

0

ara.t.howard:
> harp:~ > cat a.rb
> #!/usr/bin/env ruby -w
> p $VERBOSE
> FOO = 42 and FOO = 42
>
> harp:~ > ruby a.rb
> true
> a.rb:3: warning: already initialized constant FOO

There's no shell or anything here interpreting the shebang.

Kalman

Ara.T.Howard

1/31/2007 5:26:00 PM

0

Rob Sanheim

1/31/2007 5:50:00 PM

0

On 1/31/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Thu, 1 Feb 2007, Rob Sanheim wrote:
>
> > On 1/31/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
> >> Hi,
> >>
> >> At Thu, 1 Feb 2007 01:45:15 +0900,
> >> Rob Sanheim wrote in [ruby-talk:237036]:
> >> > I'm trying to convert some bash scripts to use /usr/bin/env ruby
> >> > instead of hardcoded shebang lines, and running into an issue. Using
> >> > this:
> >> >
> >> > #!/usr/bin/env ruby -w
> >> >
> >> > results in this error:
> >> >
> >> > /usr/bin/env: ruby -w: No such file or directory
> >>
> >> Do not rely on /usr/bin/env, it may not exist.
> >>
> >> #!/bin/sh
> >> exec ruby -x "$0" "$@"
> >> #!ruby -w
> >>
> >
> > Ugh, so I need that at the top of all these scripts? I thought
> > /usr/bin/env was the 'better' way to go?
> >
>
> you can use
>
> #! /usr/bin/env ruby
> $VERBOSE=true

That will work - thanks.

Rob Sanheim

1/31/2007 7:07:00 PM

0

On 1/31/07, Rob Sanheim <rsanheim@gmail.com> wrote:
> On 1/31/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> > On Thu, 1 Feb 2007, Rob Sanheim wrote:
> >
> > > On 1/31/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
> > >> Hi,
> > >>
> > >> At Thu, 1 Feb 2007 01:45:15 +0900,
> > >> Rob Sanheim wrote in [ruby-talk:237036]:
> > >> > I'm trying to convert some bash scripts to use /usr/bin/env ruby
> > >> > instead of hardcoded shebang lines, and running into an issue. Using
> > >> > this:
> > >> >
> > >> > #!/usr/bin/env ruby -w
> > >> >
> > >> > results in this error:
> > >> >
> > >> > /usr/bin/env: ruby -w: No such file or directory
> > >>
> > >> Do not rely on /usr/bin/env, it may not exist.
> > >>
> > >> #!/bin/sh
> > >> exec ruby -x "$0" "$@"
> > >> #!ruby -w
> > >>
> > >
> > > Ugh, so I need that at the top of all these scripts? I thought
> > > /usr/bin/env was the 'better' way to go?
> > >
> >
> > you can use
> >
> > #! /usr/bin/env ruby
> > $VERBOSE=true
>
> That will work - thanks.

My hosting provider provided this very helpful post on this whole mess:

http://elliotth.blogspot.com/2006/04/lesson-about-using-env1-in-s...

Which explains why passing in -w wasn't working, and why just setting
$VERBOSE to true isn't the same thing. Seems like it shouldn't be
this hard to get a cross platform script working, with warnings.

- Rob