Ruby is typically run from the command line as follows:
$ ruby [ options ] [.] [ programfile ] [ arguments ... ]
The interpreter can be called through the following options to control the environment and behavior of the interpreter.
Option | Description |
|---|---|
| When used with-n or-p, you can turn on automatic split mode (auto split mode). Check the-n and-p options. |
| Only check the syntax, do not execute the program. |
| Change the directory before execution (equivalent to-X). |
| Enable debug mode (equivalent to-debug). |
| Specify pat as the default detach mode ($;). |
| Specifies that prog is executed on the command line as a program. You can specify multiple-e options to execute multiple programs. |
| Displays an overview of command line options. |
| Rewrite the contents of the file as program output. The original file is saved with the extension ext. If no ext is specified, the original file is deleted. |
| Add dir as the directory to load the library. |
| Specifies the multibyte character set encoding. E or E corresponds to EUC (extended Unix code), s or S corresponds to SJIS (Shift-JIS), u or U corresponds to UTF-8,a, A, n or N corresponds to ASCII. |
| Enable automatic line end processing. Remove a newline character from the input line and append a newline character to the output line. |
| Place the code in an input loop (as in while gets;. Same in end). |
| Set the default record delimiter ($/) to octal. If octal is not specified, it defaults to0. |
| Place the code in an input loop. Output variables after each iteration $_ The value of. |
| Use require to load lib as a pre-execution library. |
| Interpret the matching pattern between the program name and the file name parameter-any parameter of xxx as a switch and define the corresponding variable. |
| Set the security level and perform an impurity test (if level is not specified, the default is 1). |
| Displays the version and enables redundancy mode. |
| Enable redundancy mode. If no program file is specified, it is read from STDIN. |
| Delete the text before the #! ruby line. If dir is specified, change the directory to dir. |
| Change the directory before execution (equivalent to-C). |
| Enable parser debug mode. |
| Displays the copyright notice. |
| Enable debug mode (equivalent to-d). |
| Displays an overview of command line options (equivalent to-h). |
| Displays the version. |
| Enable redundancy mode (equivalent to-v). Set $VERBOSE to true. |
| 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