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
... ]
-a
Used with
-n
or-p
to split each line. Split output is stored in$F
.-c
Checks syntax only, without executing program.
-C dir
Changes directory before executing (equivalent to
-X
).-d
Enables debug mode (equivalent to
-debug
). Sets$DEBUG
totrue
.-e
prog
Specifies
prog
as the program from the command line. Specify multiple-e
options for multiline programs.-F
pat
Specifies
pat
as the default separator pattern ($;
) used bysplit
.-h
Displays 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
. Ifext
isn’t specified, the original file is deleted.-I
dir
Adds
dir
as the directory for loading libraries.-K [
kcode
]
Specifies the multibyte character set code (
e
orE
for EUC (extended Unix code);s
orS
for SJIS (Shift-JIS);u
orU
for UTF-8; anda
, A,n
, orN
for ASCII).-l
Enables automatic line-end processing. Chops a newline from input lines and appends a newline to output lines.
-n
Places code within an input loop (as in
while gets; ... end
).-0[
octal
]
Sets default record separator (
$/
) as an octal. Defaults to\0
ifoctal
not specified.-p
Places code within an input loop. Writes
$_
for each ...
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.