Easy Tutorial
❮ Ruby Sending Email Ruby Hash ❯

Ruby Command Line Options

Ruby is typically run from the command line as follows:

$ ruby [ options ] [.] [ programfile ] [ arguments ... ]

The interpreter can be invoked with the following options to control its environment and behavior.

Option Description
-a Enables auto split mode when used with -n or -p. See the -n and -p options.
-c Checks syntax only, does not execute the program.
-C dir Changes directory before execution (equivalent to -X).
-d Enables debug mode (equivalent to -debug).
-F pat Specifies pat as the default split pattern ($;).
-e prog Specifies prog as the program to be executed from the command line. Multiple -e options can be specified to execute multiple programs.
-h Displays an overview of command line options.
-i [ ext] Rewrites file contents with program output. The original file is saved with the extension ext. If ext is not specified, the original file is deleted.
-I dir Adds dir as a directory to load libraries from.
-K [ kcode] Specifies the multibyte character set encoding. e or E corresponds to EUC (extended Unix code), s or S to SJIS (Shift-JIS), u or U to UTF-8, and a, A, n, or N to ASCII.
-l Enables automatic line-end processing. Removes a newline from the input line and appends a newline to the output line.
-n Places code in an input loop (as in while gets; ... end).
-0[ octal] Sets the default record separator ($/) to an octal value. If octal is not specified, it defaults to \0.
-p Places code in an input loop. Outputs the value of variable $_ after each iteration.
-r lib Requires lib as a library before execution.
-s Interprets any arguments matching the pattern -xxx between the program name and file name as switches and defines corresponding variables.
-T [level] Sets the safety level, performing impurity tests (defaults to 1 if level is not specified).
-v Displays the version and enables verbose mode.
-w Enables verbose mode. Reads from STDIN if no program file is specified.
-x [dir] Removes text before the #!ruby line. Changes directory to dir if specified.
-X dir Changes directory before execution (equivalent to -C).
-y Enables parser debug mode.
--copyright Displays the copyright notice.
--debug Enables debug mode (equivalent to -d).
--help Displays an overview of command line options (equivalent to -h).
--version Displays the version.
--verbose Enables verbose mode (equivalent to -v). Sets $VERBOSE to true.
--yydebug Enables parser debug mode (equivalent to -y).

Single-character command line options can be combined. The following two lines have the same meaning:

$ ruby -ne 'print if /Ruby/' /usr/share/bin

$ ruby -n -e 'print if /Ruby/' /usr/share/bin
❮ Ruby Sending Email Ruby Hash ❯