1

Suppose i have a ruby script that prints some message like Hello World

Now, can i make custom shell command like printMessage which passes the control to my ruby script ?

so that whenever i type printMessage from the command line, it prints Hello World ?

nik7
  • 3,018
  • 6
  • 25
  • 36
  • 3
    Making the ruby file run as executable should accomplish what you want, right? http://stackoverflow.com/questions/5518297/how-to-make-ruby-file-run-as-executable – Prakash Murthy Jan 10 '13 at 02:12
  • There are a number of ways to do this, but the question would be a better fit on http://superuser.com. – the Tin Man Jan 10 '13 at 03:03

1 Answers1

2

Add this to your .bashrc or .bash_profile

alias printMessage='ruby /path/to/file.rb'

Should do it. Unless I misunderstood the question.

And puts will print to command line. And you have to reload your bash profile once you've done this to get it to work. Just type source ~/.bashrc to reload it.

May have to chmod the file.

Alternative:

alias printMessag='ruby -e "puts \"Hello World\""'

Should work too.

hjc1710
  • 576
  • 4
  • 17