Prev - Dup - Next - TOC

Getting started


First, check whether ruby is installed or not. In the following shell prompt (we denote shell prompt by `% ', so you should not type `% '), type

 % ruby -v

(`-v' tells the interpreter to print the version of ruby), then press the ENTER key. If the next message are displayed, ruby is installed (version, date and platform may be different)

 % ruby -v
 ruby 1.1b5(98/01/19) [i486-linux]

When ruby is not installed, ask your administrator to install it. Of course you can do it yourself, ruby is free software so you can get it with no cost, and you have no restrictions on installation and it's use.

Now, let's play with ruby. You can specify the program on command line with the `-e' option.

 % ruby -le 'print "hello world\n"'
 hello world

A program of ruby can be stored in a file of course.

 % cat > test.rb
 print "hello world\n"
 ^D
 % cat test.rb
 print "hello world\n"
 % ruby test.rb
 hello world

(^D is control-D)

Ruby has a number of command line options which may be useful. Major options are listed here:

0[DIGIT] paragraph mode
a auto split mode
c syntax checking only
e SCRIPT specifies the SCRIPT on command line
F`DELIMITOR' specifies delimitor
i[extention] in-place editing mode
I DIRECTORY specities load path
l remove NEWLINE from input and put NEWLINE to output
n automatic loop
p automatic loop with output
v prints version, verbose mode

For example,

 % ruby -i.bak -pe 'sub "foo", "bar"' *.[ch]

means "replace `foo' into `bar' for all C files, preserving the original ones under name with `.bak' appended".

 % ruby -pe 0 file

`cat' whose longer name. Also it is slower than `cat' :-)


Prev - DUP - Next - TOC