Ruby command line options

Ruby is generally run from the command line as follows:

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

interpreter can be called with the following options to control the environment and behavior of the interpreter.

-a When used with -n or -p, you can turn on auto split mode. Check out the -n and -p options.
-c Checks only the syntax and does not execute the program.
-C dir Change the directory before execution (equivalent to -X).
-d Enable debug mode (equivalent to -debug).
-F pat Specify pat as the default split mode ($;).
-e prog Specifies that prog is executed as a program on the command line. Multiple -e options can be specified to execute multiple programs.
-h Displays an overview of the command line options.
-i [ ext] Rewrites the contents of the file to 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 to load the library.
-K [ kcode] Specifies multi-byte 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, and a, A, n or N corresponds to ASCII.
-l Enable automatic end-of-line processing. Cancel a newline from the input line and append a newline 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 ($/) to octal. If octal is not specified, the default is \0.
-p Place the code in an input loop. The value of the variable $_ is output after each iteration.
-r lib Use require to load lib as a pre-execution library.
-s Interpret the match pattern between the program name and the file name parameter - any parameter of -xxx as a switch and define the corresponding variable.
-T [level] Set the security level and perform an impurity test (if no level is specified, the default value is 1).
-v Displays the version and enables redundant mode.
-w Enables redundancy mode. If the program file is not specified, it is read from STDIN.
-x [dir] Delete the text before the #!ruby line. If dir is specified, change the directory to dir.
-X dir Change the directory before execution (equivalent to -C).
-y Enable parser debug mode.
--copyright Display the copyright notice.
--debug Enable debug mode (equivalent to -d).
--help Displays an overview of the command line options (equivalent to -h).
--version Shows the version.
--verbose Enable redundancy mode (equivalent to -v). Set $VERBOSE to true.
--yydebug Enable parser debug mode (equivalent to -y).

One-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

welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.