bulldog_in_the_dream
bulldog_in_the_dream

Reputation: 339

Installing and running a ruby script in the terminal in OSX Lion

I have a ruby script that I will use quite often, so I would like to be able to run it directly from the terminal, i.e. just open the terminal and type the name of the script like I would with ls, chmod or any other default command. I don't want to use cd to get to the script and I don't want invoke Ruby. I would simply like to type the name of the script with its argument and get the result.

Is it possible? If yes, where do I put the script? How do I tell OSX that it should treat it as one of its own default commands?

Upvotes: 0

Views: 1380

Answers (1)

Mithrandir
Mithrandir

Reputation: 25337

Yes, you can. Ruby should be installed on you Mac, lets say in /usr/bin/ruby.

Script:

#!/usr/bin/ruby

puts 'Hello world'

Save script under some name, e.h. test.ruby. Execute:

chmod +x test.ruby

Add the directory your script is in to your PATH. Done!

Upvotes: 1

Related Questions