Ruby - Command Line Options
Ruby is generally run from the command line in the following way
$ ruby [ options ] [.] [ programfile ] [ arguments ... ] |
The interpreter can be invoked with any of the following options to control the environment and behavior of the interpreter.
Sr.No. | Option & Description |
---|---|
1 |
-a Used with -n or -p to split each line. Check -n and -p options. |
2 |
-c Checks syntax only, without executing program. |
3 |
-C dir Changes directory before executing (equivalent to -X). |
4 |
-d Enables debug mode (equivalent to -debug). |
5 |
-F pat Specifies pat as the default separator pattern ($;) used by split. |
6 |
-e prog Specifies prog as the program from the command line. Specify multiple -e options for multiline programs. |
7 |
-h Displays an overview of command-line options. |
8 |
-i [ ext] Overwrites the file contents with program output. The original file is saved with the extension ext. If ext isn't specified, the original file is deleted. |
9 |
-I dir Adds dir as the directory for loading libraries. |
10 |
-K [ kcode] Specifies the multibyte character set code (e or E for EUC (extended Unix code); s or S for SJIS (Shift-JIS); u or U for UTF8; and a, A, n, or N for ASCII). |
11 |
-l Enables automatic line-end processing. Chops a newline from input lines and appends a newline to output lines. |
12 |
-n Places code within an input loop (as in while gets; ... end). |
13 |
-0[ octal] Sets default record separator ($/) as an octal. Defaults to \0 if octal not specified. |
14 |
-p Places code within an input loop. Writes $_ for each iteration. |
15 |
-r lib Uses require to load lib as a library before executing. |
16 |
-s Interprets any arguments between the program name and filename arguments fitting the pattern -xxx as a switch and defines the corresponding variable. |
17 |
-T [level] Sets the level for tainting checks (1 if level not specified). |
18 |
-v Displays version and enables verbose mode. |
19 |
-w Enables verbose mode. If program file not specified, reads from STDIN. |
20 |
-x [dir] Strip text before #!ruby line. Changes directory to dir before executing if dir is specified. |
21 |
-X dir Changes directory before executing (equivalent to -C). |
22 |
-y Enables parser debug mode. |
23 |
--copyright Displays copyright notice. |
24 |
--debug Enables debug mode (equivalent to -d). |
25 |
--help Displays an overview of command-line options (equivalent to h). |
26 |
--version Displays version. |
27 |
--verbose Enables verbose mode (equivalent to -v). Sets $VERBOSE to true. |
28 |
--yydebug Enables parser debug mode (equivalent to -y). |
Single character command-line options can be combined. The following two lines express the same meaning
$ruby -ne 'print if /Ruby/' /usr/share/bin $ruby -n -e 'print if /Ruby/' /usr/share/bin |
Ruby program to add two integer numbers
how to create an array with Array.[](*args) in Ruby ?
What are the various Ruby runtimes, and how are they different?
Ruby program to check whether the given number is prime or not
Ruby program to reverse a string
Ruby program to check whether the given number is palindrome
Ruby program to print Fibonacci series
How to Replace array elements in Ruby?
Ruby program to print an array
Ruby program to check whether the given number is Armstrong
Program to Print Triangle of Numbers in Ruby
How to add/remove elements to Array in Ruby?
How to shuffle an array in Ruby?
Creating Array with Array.new(size, obj) in Ruby
Ruby program to generate random numbers
Ruby program to Calculate the factorial of given number
What are #method_missing and #send? Why are they useful?
How to Sort Array in Ruby?
How to get index of array element in Ruby
How to Get Input with Gets in Ruby
How to create two dimensional array in ruby?