Shebang! line not recognized in OS X Leopard??

J

Johnnie Lieske

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!
 
B

brabuhr

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
?
 
T

Tim Hunter

Johnnie said:
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!

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
 
J

Johnnie Lieske

Tim said:
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!"



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

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

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


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


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


Thanks all!
 
L

Laurent Sansonetti

Thanks Tim.

None of that worked.

Here is the script that I have:

#!/usr/bin/ruby
puts "Hello, Matz!"




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


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


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



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


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

Works for me :)

$ 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
 
L

List.rb

On Nov 27, 2008, at 9:26 PM, "Laurent Sansonetti" <[email protected]
wrote:
Thanks Tim.

None of that worked.

Here is the script that I have:

#!/usr/bin/ruby
puts "Hello, Matz!"




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


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


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



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


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

Works for me :)

$ 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


Try dos2unix on the file then rerun?
 
J

Johnnie Lieske

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top