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|
Used with -n or -p to split each line. Check -n and -p options.
Checks syntax only, without executing program.
Changes directory before executing (equivalent to -X).
Enables debug mode (equivalent to -debug).
Specifies pat as the default separator pattern ($;) used by split.
Specifies prog as the program from the command line. Specify multiple -e options for multiline programs.
Displays an overview of command-line options.
-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.
Adds dir as the directory for loading libraries.
-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).
Enables automatic line-end processing. Chops a newline from input lines and appends a newline to output lines.
Places code within an input loop (as in while gets; ... end).
Sets default record separator ($/) as an octal. Defaults to \0 if octal not specified.
Places code within an input loop. Writes $_ for each iteration.
Uses require to load lib as a library before executing.
Interprets any arguments between the program name and filename arguments fitting the pattern -xxx as a switch and defines the corresponding variable.
Sets the level for tainting checks (1 if level not specified).
Displays version and enables verbose mode.
Enables verbose mode. If program file not specified, reads from STDIN.
Strip text before #!ruby line. Changes directory to dir before executing if dir is specified.
Changes directory before executing (equivalent to -C).
Enables parser debug mode.
Displays copyright notice.
Enables debug mode (equivalent to -d).
Displays an overview of command-line options (equivalent to h).
Enables verbose mode (equivalent to -v). Sets $VERBOSE to true.
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?