Forum: Ruby Shebang! line not recognized in OS X Leopard??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6534280e2bdd4d98f37535766fc38193?d=identicon&s=25 Johnnie Lieske (pinkfrankenstein)
on 2008-11-27 17:09
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!
E0c987f680cd640c14912ebfbf0f0f07?d=identicon&s=25 unknown (Guest)
on 2008-11-27 17:18
(Received via mailing list)
On Thu, Nov 27, 2008 at 11:04 AM, Johnnie Lieske
<generic@frankenstein.com> 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
?
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2008-11-27 17:18
(Received via mailing list)
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
6534280e2bdd4d98f37535766fc38193?d=identicon&s=25 Johnnie Lieske (pinkfrankenstein)
on 2008-11-27 17:41
Tim Hunter 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!
Dc32e0513d1a0b086d2afa9311e9e472?d=identicon&s=25 Laurent Sansonetti (Guest)
on 2008-11-28 03:32
(Received via mailing list)
On Thu, Nov 27, 2008 at 8:36 AM, Johnnie Lieske
<generic@frankenstein.com> 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 :-)

$ 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
990bf71a4e84e1145a3131f35656dc18?d=identicon&s=25 List Rb (listx300108u79872)
on 2008-11-28 04:15
(Received via mailing list)
On Nov 27, 2008, at 9:26 PM, "Laurent Sansonetti"
<laurent.sansonetti@gmail.com
 > wrote:

>>> normally
>>
>> total 8
>> Pinky:rubes pink$ ./matz.rb
>>
> Hello, Matz!
>
Try dos2unix on the file then rerun?
6534280e2bdd4d98f37535766fc38193?d=identicon&s=25 Johnnie Lieske (pinkfrankenstein)
on 2008-11-28 15:30
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 Sansonetti"
> <laurent.sansonetti@gmail.com
>  > wrote:
>
>>>> normally
>>>
>>> total 8
>>> Pinky:rubes pink$ ./matz.rb
>>>
>> Hello, Matz!
>>
> Try dos2unix on the file then rerun?
This topic is locked and can not be replied to.