Ruby interpreter accepts following command-line options (switches). Basically they are quite similar to those of Perl.
$/
) 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
value.
at beginning of each loop.$F = $_.split
$DEBUG
will set TRUE.
$;
).
example:
% echo matz > /tmp/junk % cat /tmp/junk matz % ruby -p -i.bak -e '$_.upcase!' /tmp/junk % cat /tmp/junk MATZ % cat /tmp/junk.bak matz
$:
').
$\
to the value of $/
,
and secondly chops every line read using chop!
.
while gets ... end
-n
switch, but print the value of variable
$_
at the each end of the loop.
example:
% echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"' MATZ
require
. It is
useful with switches -n or -p.
example:
#! /usr/local/bin/ruby -s # prints "true" if invoked with `-xyz' switch. print "true\n" if $xyz
#! /usr/local/bin/ruby # This line makes the next one a comment in ruby \ exec /usr/local/bin/ruby -S $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.
To handle embedded spaces or such, A better construct than
$*
would be ${1+"$@"}
, but it does
not work if the script is being interpreted by csh.
$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
version.
$VERBOSE
' to
TRUE.
^D
(control-D), ^Z
(control-Z), or reserved word __END__
.If the
directory name is specified, ruby will switch to that
directory before executing script.