[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

"ruby myscript.rb" Works, "./myscript.rb" Doesn't

Nathan O.

3/9/2006 8:36:00 PM

I have a script. When I run it via "ruby myscript.rb", it works great.
When I run it via "./myscript.rb", it complains:

: No such file or directory.

The top of the file starts with "#!/usr/bin/env ruby", which works for
other scripts in the same directory. I know it's spelled right. And the
file is set executable.

The colon (":") at the start of the error message makes me think it's
looking for a file with no name when it should be looking for my script.
Again, the script works great when run as a param to the "ruby..."
command.

--
Posted via http://www.ruby-....


11 Answers

Michael Gorsuch

3/9/2006 8:52:00 PM

0

Did you "chmod +x" the script?

On 3/9/06, Nathan O. <nathan.olberding@gmail.com> wrote:
> I have a script. When I run it via "ruby myscript.rb", it works great.
> When I run it via "./myscript.rb", it complains:
>
> : No such file or directory.
>
> The top of the file starts with "#!/usr/bin/env ruby", which works for
> other scripts in the same directory. I know it's spelled right. And the
> file is set executable.
>
> The colon (":") at the start of the error message makes me think it's
> looking for a file with no name when it should be looking for my script.
> Again, the script works great when run as a param to the "ruby..."
> command.
>
> --
> Posted via http://www.ruby-....
>
>


Michael Gorsuch

3/9/2006 8:53:00 PM

0

Sorry. I just noticed that it is already executable.

What if you use the path straight to the ruby interpreter, and not /usr/bin/env?

On 3/9/06, Michael Gorsuch <michael.gorsuch@gmail.com> wrote:
> Did you "chmod +x" the script?
>
> On 3/9/06, Nathan O. <nathan.olberding@gmail.com> wrote:
> > I have a script. When I run it via "ruby myscript.rb", it works great.
> > When I run it via "./myscript.rb", it complains:
> >
> > : No such file or directory.
> >
> > The top of the file starts with "#!/usr/bin/env ruby", which works for
> > other scripts in the same directory. I know it's spelled right. And the
> > file is set executable.
> >
> > The colon (":") at the start of the error message makes me think it's
> > looking for a file with no name when it should be looking for my script

Nathan O.

3/9/2006 9:04:00 PM

0

> What if you use the path straight to the ruby interpreter, and not
> /usr/bin/env?

Very interesting! When I change /usr/bin/env ruby to /usr/bin/ruby
(which is where the binary is), I get:

: bad interpreter: No such file or directory

--
Posted via http://www.ruby-....


Michael Gorsuch

3/9/2006 9:08:00 PM

0

wtf?

There isn't any whitespace or blank lines before:

#!/usr/bin/ruby

is there?

On 3/9/06, Nathan Olberding <nathan.olberding@gmail.com> wrote:
> > What if you use the path straight to the ruby interpreter, and not
> > /usr/bin/env?
>
> Very interesting! When I change /usr/bin/env ruby to /usr/bin/ruby
> (which is where the binary is), I get:
>
> : bad interpreter: No such file or directory
>
> --
> Posted via http://www.ruby-....
>
>


Tim Hunter

3/9/2006 9:13:00 PM

0

Whenever I get weird messages like this it always turns out to be a
problem with line endings. By any chance did you last save the file on
a Windows system?

Nathan O.

3/9/2006 9:15:00 PM

0

Michael Gorsuch wrote:
> wtf?

I'm glad we're on the same page. :-) Now I don't feel so alone!

> There isn't any whitespace or blank lines before:
>
> #!/usr/bin/ruby
>
> is there?

nathan@vm1:~/public_html$ head -1 myscript.rb
#!/usr/bin/ruby
nathan@vm1:~/public_html$

Nada.

--
Posted via http://www.ruby-....


jh+ruby-lang

3/9/2006 9:17:00 PM

0

Michael Gorsuch wrote:
> wtf?
>
> There isn't any whitespace or blank lines before:
>
> #!/usr/bin/ruby
>
> is there?
>
> On 3/9/06, Nathan Olberding <nathan.olberding@gmail.com> wrote:
>>> What if you use the path straight to the ruby interpreter, and not
>>> /usr/bin/env?
>> Very interesting! When I change /usr/bin/env ruby to /usr/bin/ruby
>> (which is where the binary is), I get:
>>
>> : bad interpreter: No such file or directory

Your script has been on a Windows box or otherwise polluted with a \r
(Carriage return) after ruby?

The kernel can't find /usr/bin/ruby\r

-jonathan

Anthony DeRobertis

3/9/2006 9:21:00 PM

0

Nathan O.

3/9/2006 9:30:00 PM

0

> Your script has been on a Windows box or otherwise polluted with a \r
> (Carriage return) after ruby?

That's it, that's the one. I had this problem with another script the
other day. It "went away" after I did a whole bunch of stuff. This
must've been it.

2006, and we're still dealing with line endings :-)

How do I convert it?

--
Posted via http://www.ruby-....


Mike

3/9/2006 9:33:00 PM

0

Nathan Olberding wrote:
> How do I convert it?

Try dos2unix

-M

--
Posted via http://www.ruby-....