Command-Line Options
Like most scripting language interpreters, Ruby is generally run from the command line. The interpreter can be invoked with the following options, which control the environment and behavior of the interpreter itself:
ruby [options] [—] [programfile] [argument... ]
-aUsed with
-nor-pto split each line. Split output is stored in$F.-cChecks syntax only, without executing program.
-C dirChanges directory before executing (equivalent to
-X).-dEnables debug mode (equivalent to
-debug). Sets$DEBUGtotrue.-eprogSpecifies
progas the program from the command line. Specify multiple-eoptions for multiline programs.-FpatSpecifies
patas the default separator pattern ($;) used bysplit.-hDisplays an overview of command-line options (equivalent to
-help).-i [ext]Overwrites the file contents with program output. The original file is saved with the extension
ext. Ifextisn’t specified, the original file is deleted.-IdirAdds
diras the directory for loading libraries.-K [kcode]Specifies the multibyte character set code (
eorEfor EUC (extended Unix code);sorSfor SJIS (Shift-JIS);uorUfor UTF-8; anda, A,n, orNfor ASCII).-lEnables automatic line-end processing. Chops a newline from input lines and appends a newline to output lines.
-nPlaces code within an input loop (as in
while gets; ... end).-0[octal]Sets default record separator (
$/) as an octal. Defaults to\0ifoctalnot specified.-pPlaces code within an input loop. Writes
$_for each ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access