-1

I have a Ruby script in lib/my_file.rb. I want to run this file when someone cds into the directory and enters start_project.

To run a Ruby file, we should use ruby filename.rb, but how do I run a file using a command that in turn translates to "ruby filename.rb".

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Mahendhar
  • 1
  • 2

1 Answers1

0

It depends for the most part what you are trying to accomplish.

If you want to use this as a shortcut on your machine, you can add an alias to your .bash_profile or .bashrc like so:

alias start_project='ruby filename.rb'

or add a function:

function start_project {
  ruby filename.rb
}

If this is part of a repo, you probably want a file in your repo to do this. We can write a bash script for that:

#!/bin/bash          
ruby filename.rb  

If the bash script is called start_project.sh you can call it by by typing ./start_project.sh as long as you provide executable permissions (see "bash Permissions").

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Justin Hellreich
  • 575
  • 5
  • 15
  • Thank you @Justin. I did as you suggested and it works. Right now, I am doing `./start_project.sh`. Is there any way in which I can just enter `start_project` and it runs the ruby file? – Mahendhar Feb 13 '17 at 21:37
  • [This](http://stackoverflow.com/questions/8779951/how-do-i-run-a-shell-script-without-using-sh-or-bash-commands) question should help, although I've never tried it. – Justin Hellreich Feb 13 '17 at 21:49