This explanation is based on a commented ruby script from a friend of mine.
Run ruby script from command line.
The following instructions have been tested with windows 8 and 8 1.
Here are ways to execute a shell script.
Ruby is generally run from the command line in the following way ruby options programfile arguments.
The terminal has a rich set of powerful tools that are accessible by typing the commands.
Test rb test1 test2 you may encounter a situation in which you need to pass an argument to a ruby program but there s a space in the command.
If you want to improve the script feel free to update it at the link.
One off ruby scripts run the gamut on the services they can provide you.
To run ruby on windows you have to install ruby and several developer tools.
The following example shows the proper syntax to use to launch the test rb ruby script from a command line with the arguments test1 and test2.
Otherwise execute the interpreter and pass it the script as an argument ruby myscript rb if you want to run the script from anywhere using a simple command wrap one of these.
Open a command line window and navigate to your ruby scripts directory using the cd command.
Go to ruby installer in your web browser.
From little helpers to full on command line utilities the possibilities are endless.
If the script is executable and the first line of the script is usr bin ruby or whatever the path to your ruby interpreter might be then you should be able to launch the script directly i e.
Click the big red download button.
You ll be able to gets from and puts to the command line now.
Some bash syntax is not supported by bin sh on all systems.
Using the classic hello world script where all we do is print hello world to the console i m going to show you four ways in which you can write and run a script with ruby.
My script rb def say input puts what should we say.
Once there you can list files using the dir command on windows or the ls command on linux or os x.
A list of rubyinstallers appears.
To run the test rb ruby script run the command ruby test rb.
It s easy just create a file with the extension rb navigate to that file s directory from the command line and run it using ruby filename rb the dollar sign is just the command prompt.
Once you can see for example script1 sh with ls run this script sh why do it the complicated way.
Click ruby 2 2 2 near the top of the rubyinstallers list.
The interpreter can be invoked with any of the following options to control the environment and behavior of the interpreter.
First note that when ruby calls out to a shell it typically calls bin sh not bash.
Once you are in the correct current folder you can run the script like this script1 sh.