Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Ruby script into a bash command?

Tags:

bash

ruby

shebang

I have a Ruby file, and I run it as ruby file.rb "parameters". I prefer to run it as regtask parameters without having to include ruby and the filename every time. I want it to be on the same level as ls. How would I accomplish this?

like image 628
Doug Smith Avatar asked Jan 19 '15 05:01

Doug Smith


Video Answer


1 Answers

Edit your file, make sure this is the first line, so your system knows how to execute your file:

#!/usr/bin/env ruby

Next, change the file's permissions to make it executable:

chmod a+x file.rb

And finally, rename it and move it somewhere where it will be executed without having to write its full path:

mkdir -p ~/bin
mv file.rb ~/bin/regtask

(Most systems will automatically add ~/bin to PATH if it exists; if not, you will have to add it to PATH yourself in your startup files.)

like image 150
Amadan Avatar answered Sep 20 '22 20:09

Amadan