Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Ruby Programming
Previous Page Home Next Page

Command-Line Options

' The number ``0'' flag specifies the record separator character (\0, if no digit follows). -00 indicates paragraph mode: records are separated by two successive default record separator characters. -0777 reads the entire file at once (as it is an illegal character). Sets $/.

' Auto split mode when used with -n or -p; equivalent to executing {$F at the top of each loop iteration.

-C directory
' Changes working directory to directory before executing.

' Checks syntax only; does not execute the program.

Prints the copyright notice and exits.

-d, --debug
' Sets $DEBUG to true. This can be used by your programs to enable additional tracing.

-e 'command'
' Executes command as one line of Ruby source. Several -e's are allowed, and the commands are treated as multiple lines in the same program. If programfile is omitted when -e is present, execution stops after the -e commands have been run.

-F pattern
' Specifies the input field separator ($;) used as the default for split() (affects -a).

-h, --help
' Displays a short help screen.

-I directories
' Specifies directories to be prepended to $LOAD_PATH ($:). Multiple -I options may be present, and multiple directories may appear following each -I. Directories are separated by a ``:'' on Unix-like systems and by a ``;'' on DOS/Windows systems.

-i [extension}
' Edits ARGV files in place. For each file named in ARGV, anything you write to standard output will be saved back as the contents of that file. A backup copy of the file will be made if extension is supplied.
% ruby -pi.bak -e "gsub(/Perl/, 'Ruby')" *.txt

-K kcode
' Specifies the code set to be used. This option is useful mainly when Ruby is used for Japanese-language processing. kcode may be one of: e, E for EUC; s, S for SJIS; u, U for UTF-8; or a, A, n, N for ASCII.

' Enables automatic line-ending processing; sets $\ to the value of $/ and chops every input line automatically.

' Assumes ``while gets; ...; end'' loop around your program. For example, a simple grep command might be implemented as:
% ruby -n -e "print if /wombat/"  *.txt

' Places your program code within the loop ``while gets; ...; print; end.''
% ruby -p -e "$_.downcase!" *.txt
-r library
' requires the named library before executing.

' Looks for the program file using RUBYPATH or PATH environment variable.

' Any command line switches found after the program filename, but before any filename arguments or before a --, are removed from ARGV and set to a global variable named for the switch. In the following example, the effect of this would be to set the variable $opt to ``electric''.

% ruby -s prog -opt=electric ./mydata

' Sets the safe level, which among other things enables tainting checks (see page 253). Sets $SAFE.

-v, --verbose
' Enables verbose mode and print the version number. In verbose mode, compilation warnings are printed. If no program filename appears on the command line, Ruby exits.

Displays the Ruby version number and exits.

' Enables verbose mode. Unlike -v, reads program from standard input if no program files are present on the command line. We recommend running your Ruby programs with -w.

-X directory
' Changes working directory to directory before executing. Same as -C directory.

-x [directory}
' Strips off text before #!ruby line and changes working directory to directory if given.

-y, --yydebug
' Enables yacc debugging in the parser (waaay too much information).
Ruby Programming
Previous Page Home Next Page

  Published under the terms of the Open Publication License Design by Interspire