Command line options
Ruby interpreter accepts following command-line options
(switches). Basically they are quite similar to those of
specifies the input record separator (
$/) as an
octal number. If no digits given, the null character is the
separator. Other switches may follow the digits.
-00 turns Ruby into paragraph mode.
-0777 makes Ruby read whole file at once as a
single string, since there is no legal character with that
turns on auto-split mode when used with -n or
-p. In auto-split mode, Ruby executes
$F = $_.split
at beginning of each loop.
causes Ruby to check the syntax of the script and exit
without executing. If there is no syntax error, Ruby will
print "Syntax OK" to the standard output.
specifies KANJI (Japanese character) code-set.
turns on debug mode.
$DEBUG will set true.
- -e script
specifies script from command-line. if -e
switch specified, Ruby will not look for a script filename
in the arguments.
- -F regexp
specifies input field separator (
prints a summary of the options.
- -i extension
specifies in-place-edit mode. The extension, if specified,
is added to old filename to make a backup copy.
% echo matz > /tmp/junk
% cat /tmp/junk
% ruby -p -i.bak -e '$_.upcase!' /tmp/junk
% cat /tmp/junk
% cat /tmp/junk.bak
used to tell Ruby where to load the library scripts.
Directory path will be added to the load-path variable
enables automatic line-ending processing, which means
$\ to the value of
and secondly chops every line read using
when used with
causes Ruby to assume the following loop around your script,
which makes it iterate over filename arguments somewhat like
sed -n or awk.
acts mostly same as
-n switch, but print the value of variable
$_ at the each end of the loop.
% echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"'
- -r filename
causes Ruby to load the file using
require. It is
useful with switches -n or -p.
enables some switch parsing for switches after script name
but before any filename arguments (or before a
--). Any switches found there is removed from
ARGV and set the corresponding variable in the script.
#! /usr/local/bin/ruby -s
# prints "true" if invoked with `-xyz' switch.
print "true\n" if $xyz
makes Ruby uses the PATH environment variable to search for
script, unless if its name begins with a slash.
This is used to emulate #! on machines that
don't support it, in the following manner:
exec ruby -S -x $0 "$@"
On some systems $0 does not always contain the full
pathname, so you need -S switch to tell Ruby to
search for the script if necessary.
- -T [level]
Forces "taint" checks to be turned on so you can test them. If level
$SAFE to be set to that level. It's a good
idea to turn them on explicitly for programs run on another's behalf,
such as CGI programs.
enables verbose mode. Ruby will prints its version at the beginning,
and set the variable `
$VERBOSE' to true. Some methods
prints extra messages if this variable is true. If this switch is
given, and no other switches present, Ruby quits after printing its
prints the version of Ruby executable.
enables verbose mode without printing version message at the
beginning. It set the variable `
$VERBOSE' to true.
tells Ruby that the script is embedded in a message. Leading garbage
will be discarded until the first that starts with "#!" and contains
string "ruby". Any meaningful switches on that line will applied. The
end of script must be specified with either EOF,
^Z (control-Z), or reserved word
__END__.If the directory name is specified, Ruby will
switch to that directory before executing script.
- -X directory
causes Ruby to switch to the directory.
turns on compiler debug mode. Ruby will print bunch of internal state
messages during compiling scripts. You don't have to specify this
switch, unless you are going to debug the Ruby interpreter itself.