English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Ruby is generally run from the command line, as follows:
$ ruby [ options ] [.] [ programfile ] [ arguments ... ]
The interpreter can be called with the following options to control the environment and behavior of the interpreter.
options | description |
---|---|
-a | with -n or -p together can open the automatic split mode (auto split mode). Please see -n and -p option. |
-c | Check syntax only, do not execute the program. |
-C dir | Change directory before execution (equivalent to -X). |
-d | Enable debug mode (equivalent to -debug). |
-F pat | Specify pat as the default split mode ($;). |
-e prog | Specify prog as the program to be executed on the command line. Multiple -e option to execute multiple programs. |
-h | Display an overview of the command line options. |
-i [ ext] | Rewrite the file content to the program output. The original file will be saved with the extension ext. If ext is not specified, the original file will be deleted. |
-I dir | Add dir as the directory for loading libraries. |
-K [ kcode] | Specify the encoding of the multibyte character set. e or E corresponds to EUC (extended Unix code), s or S corresponds to SJIS(Shift-JIS), u or U correspond to UTF-8, a, A, n, or N correspond to ASCII. |
-l | Enable automatic line end processing. Remove a newline character from the input line and append a newline character to the output line. |
-n | Place the code in an input loop (just like in while gets; ... end). |
-0[ octal] | Set the default record separator ($/) as octal. If octal is not specified, the default is \0. |
-p | Place the code in an input loop. Output the value of the variable $_ after each iteration. |
-r lib | use require to load lib as the library before execution. |
-s | Interpret the matching pattern between the program name and file name parameters -xxx any parameters as switches, and define the corresponding variables. |
-T [level] | Set security level, perform purity test (if level is not specified, the default value is 1) |
-v | Display version and enable redundancy mode. |
-w | Enable redundancy mode. If the program file is not specified, read from STDIN. |
-x [dir] | Delete the text before the #!ruby line. If specified dirIf specified, change the directory to dir. |
-X dir | Change directory before execution (equivalent to -C). |
-y | Enable parser debug mode. |
--copyright | Display copyright statement. |
--debug | Enable debug mode (equivalent to -d). |
--help | Display an overview of command line options (equivalent to -h). |
--version | Display version. |
--verbose | Enable verbose mode (equivalent to -v). Set $VERBOSE to true. |
--yydebug | Enable 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