Calling ruby scripts

Usually I can put

#! /usr/bin/env ruby

in the first line of a script and it works fine. However, this doesn’t
work:

#! /usr/bin/env ruby

class Hello
attr_reader :msg
def initialize
@msg = "Hello, World"
end
end

h = Hello.new
puts h.msg

$ hello
: No such file or directory

However,

ruby hello

works fine. What am I missing?

Bob Peirce Venetia, PA
724-941-6883
bob@peirce-family.com [HOME (Mac)]
rbp@cooksonpeirce.com [OFFICE]

There is only one basic human right, the right to do as you damn well
please. And with it comes the only basic human duty, the duty to take
the consequences. – P.J. O’Rourke

if you are on linux/unix

works fine. What am I missing?

the ./ (dot slash) to indicate where you executable resides
$chmod +x hello
$./hello

Robert Peirce wrote:

···

Usually I can put

#! /usr/bin/env ruby

in the first line of a script and it works fine. However, this
doesn’t work:

#! /usr/bin/env ruby

class Hello
attr_reader :msg
def initialize
@msg = “Hello, World”
end
end

h = Hello.new
puts h.msg

$ hello
: No such file or directory

However,

ruby hello

Bob Peirce Venetia,
PA 724-941-6883
bob@peirce-family.com [HOME (Mac)]
rbp@cooksonpeirce.com [OFFICE]

There is only one basic human right, the right to do as you damn well
please. And with it comes the only basic human duty, the duty to take
the consequences. – P.J. O’Rourke


General Electric - CIAT
Advanced Engineering Center


Rodrigo Bermejo
Information Technologies.
Special Applications
Dial-comm : *879-0644
Phone :(+52) 442-196-0644

in the first line of a script and it works fine. However, this doesn’t=20=

work:

#! /usr/bin/env ruby

However,

ruby hello

works fine. What am I missing?

What happens if you type “/usr/bin/env ruby --version” on the command
line? Is it possible you’ve seen it work on other computers, but env
isn’t installed on this particular one?

Joe

···

In article 4FBD898C-6E3E-11D8-8A65-000393CE35A6@peirce-family.com, Robert Peirce wrote:

Hi,

At Fri, 5 Mar 2004 09:44:55 +0900,
Robert Peirce wrote in [ruby-talk:94276]:

$ hello
: No such file or directory

I vote line ending code issue.

···


Nobu Nakada

That’s not it. I have hello and tst1 through tst7. They are all
executable and all have the same first line. All but hello work with a
direct call. There is something about this script that is causing a
problem:

$ cat hello
#! /usr/bin/env ruby

class Hello
attr_reader :msg
def initialize
@msg = “Hello, World”
end
end

h = Hello.new
puts h.msg

···

On Mar 4, 2004, at 7:56 PM, Bermejo, Rodrigo wrote:

if you are on linux/unix

works fine. What am I missing?

the ./ (dot slash) to indicate where you executable resides
$chmod +x hello
$./hello

That’s not it. I am using the same first line in several other scripts.

$ /usr/bin/env ruby --version
ruby 1.6.8 (2002-12-24) [powerpc-darwin7.0]

···

On Mar 4, 2004, at 8:09 PM, Joe Mason wrote:

In article 4FBD898C-6E3E-11D8-8A65-000393CE35A6@peirce-family.com,
Robert Peirce wrote:

What happens if you type “/usr/bin/env ruby --version” on the command
line? Is it possible you’ve seen it work on other computers, but env
isn’t installed on this particular one?

That was it!! Hello came from a Windows machine where lines end in
\n\r. I was trying to run it on a Unix machine where lines end in \n.
I ran ‘cat hello | tr -d ‘\r’ > tst8’, made tst8 executable and it ran.
Thanks.

Apparently, ruby itself ignores this, which is why ‘ruby hello’ worked.

···

On Mar 4, 2004, at 8:33 PM, nobu.nokada@softhome.net wrote:

Hi,

At Fri, 5 Mar 2004 09:44:55 +0900,
Robert Peirce wrote in [ruby-talk:94276]:

$ hello
: No such file or directory

I vote line ending code issue.


Nobu Nakada

Hi,

At Fri, 5 Mar 2004 10:44:13 +0900,
Robert Peirce wrote in [ruby-talk:94288]:

Apparently, ruby itself ignores this, which is why ‘ruby hello’ worked.

Yes, but the OS kernel doesn’t nor env doesn’t strip it. You
can put a space at end of the line.

···


Nobu Nakada

Have a look at the command “recode”, which is availiable on most linux
systems, see http://recode.progiciels-bpi.ca/manual/IBM-PC.html.

“recode pc hello” should do for your case.

Cheers
Sascha

···

Robert Peirce bob@peirce-family.com wrote:

I ran ‘cat hello | tr -d ‘\r’ > tst8’, made tst8 executable and it ran.

  • Robert Peirce; Fri, 5 Mar 2004 10:44:13 +0900

I ran ‘cat hello | tr -d ‘\r’ > tst8’, made tst8 executable and it
ran.

Any to any conversion:

DOS → UNIX: ruby -p -i.bak -e ‘$.sub!(/\r$/,“”)’ file_name
DOS → Mac: ruby -n -i.bak -e 'print $
.chomp+“\r”’

UNIX → DOS: ruby -p -i.bak -e ‘$.sub!(/$/,“\r”)’ file_name
UNIX → Mac: ruby -n -i.bak -e 'print $
.chomp+“\r”’

Mac → UNIX: ruby -p -i.bak -e ‘$.gsub!(/\r/,“\n”)’ file_name
Mac → DOS: ruby -p -i.bak -e '$
.gsub!(/\r/,“\r\n”)’

Josef ‘Jupp’ Schugt

···

On Mar 4, 2004, at 8:33 PM, nobu.nokada@softhome.net wrote:

I’m running BSD on a Mac PowerBook G4. However, Uwin (Unix for
Windows) has the -d and -D flags to cat that can add/remove ‘\r’.

I suppose it would be easy to write a shell script, called recode that
would do these things. I already have one called rename that allows,
for example, changing file1…file9 to file01…file09.

One of the beauties of Unix and its many variants is that it makes text
manipulation easy. Ruby seems to have similar, maybe even more
powerful, capabilities in this area, which is one of the reasons I am
trying to learn it.

···

On Mar 5, 2004, at 3:49 AM, Sascha D?rdelmann wrote:

Robert Peirce bob@peirce-family.com wrote:

I ran ‘cat hello | tr -d ‘\r’ > tst8’, made tst8 executable and it
ran.

Have a look at the command “recode”, which is availiable on most linux
systems, see http://recode.progiciels-bpi.ca/manual/IBM-PC.html.

“recode pc hello” should do for your case.

you can safely omit $, just use Kernel#gsub that is $.gsub by itself

···

il 7 Mar 2004 00:36:04 GMT, Josef ‘Jupp’ Schugt jupp@gmx.de ha scritto::

Any to any conversion:

DOS → UNIX: ruby -p -i.bak -e ‘$.sub!(/\r$/,“”)’ file_name
DOS → Mac: ruby -n -i.bak -e 'print $
.chomp+“\r”’

UNIX → DOS: ruby -p -i.bak -e ‘$.sub!(/$/,“\r”)’ file_name
UNIX → Mac: ruby -n -i.bak -e 'print $
.chomp+“\r”’

Mac → UNIX: ruby -p -i.bak -e ‘$.gsub!(/\r/,“\n”)’ file_name
Mac → DOS: ruby -p -i.bak -e '$
.gsub!(/\r/,“\r\n”)’