Shebang! line not recognized in OS X Leopard?

Hi

Newbie to Ruby.

Going through the O’Reily book I get this bit of code for creating a
hello world script. The shebang line is suppossed to make it so I don’t
have to type “ruby” before executing my scripts:

#!/usr/local/bin/ruby

a nice greeting for Matz

puts “Hello, Matz!”

Problem is that I get this when I run the script:

Pinky:rubes pink$ matz.rb
-bash: matz.rb: command not found

I’ve searched everywhere for an answer but probably don’t know how to
pose the question.

The path to ruby on my computer is actually /usr/bin/ruby and not
/usr/local/bin/ruby

I change the code in the script but still get the same error.

It’s stupid but I am anal and feel like I can’t go on…

Any help greatly appreciated.

Thanks!

On Thu, Nov 27, 2008 at 11:04 AM, Johnnie Lieske
[email protected] wrote:

Pinky:rubes pink$ matz.rb
-bash: matz.rb: command not found

Assuming matz.rb is in your current directory, try:
./matz.rb

Did you already:
chmod +x matz.rb
?

Johnnie Lieske wrote:

puts “Hello, Matz!”

The path to ruby on my computer is actually /usr/bin/ruby and not
/usr/local/bin/ruby

I change the code in the script but still get the same error.

It’s stupid but I am anal and feel like I can’t go on…

Any help greatly appreciated.

Thanks!

You should use the actual path to ruby on your computer. Also, make sure
your script has its executable bit set:

chmod +x matz.rb

And finally, OS X only looks for executables your $PATH, which normally
doesn’t include your current directory. To execute a script in the
current directory, do this:

./matz.rb

Tim H. wrote:

You should use the actual path to ruby on your computer. Also, make
sure
your script has its executable bit set:

chmod +x matz.rb

And finally, OS X only looks for executables your $PATH, which normally
doesn’t include your current directory. To execute a script in the
current directory, do this:

./matz.rb

Thanks Tim.

None of that worked.

Here is the script that I have:

#!/usr/bin/ruby
puts “Hello, Matz!”

here is info on the ruby path and the permissions of matz.rb

Pinky:rubes pink$ which ruby
/usr/bin/ruby
Pinky:rubes pink$ ls -l
total 8
-rwxr-xr-x@ 1 pink staff 41 Nov 27 08:00 matz.rb

this is what i get when i try to run the script

Pinky:rubes pink$ matz.rb
-bash: matz.rb: command not found

this is what i get when i put ./ in front, just a prompt no out put

Pinky:rubes pink$ ./matz.rb
Pinky:rubes pink$

this always works as it should

Pinky:rubes pink$ ruby matz.rb
Hello, Matz!

the ./ made a difference but I am puzzled why there is no output.

Thanks all!

On Nov 27, 2008, at 9:26 PM, “Laurent S.”
<[email protected]

wrote:

normally

total 8
Pinky:rubes pink$ ./matz.rb

Hello, Matz!

Try dos2unix on the file then rerun?

On Thu, Nov 27, 2008 at 8:36 AM, Johnnie Lieske
[email protected] wrote:

this is what i get when i try to run the script
this always works as it should

Pinky:rubes pink$ ruby matz.rb
Hello, Matz!

the ./ made a difference but I am puzzled why there is no output.

Works for me :slight_smile:

$ cat t.rb
#!/usr/bin/ruby
puts “Hello, Matz!”
$ chmod +x t.rb
$ ./t.rb
Hello, Matz!
$ PATH=. t.rb
Hello, Matz!
$ which ruby
/usr/bin/ruby
$ ruby -v
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.5.5
BuildVersion: 9F33

Laurent

Mostly my bad.

Something about the file type got screwed up and that was where the
problem was. Creating a new file and using “./” fixed the issue.

Thanks ALL!

List Rb wrote:

On Nov 27, 2008, at 9:26 PM, “Laurent S.”
<[email protected]

wrote:

normally

total 8
Pinky:rubes pink$ ./matz.rb

Hello, Matz!

Try dos2unix on the file then rerun?