#! /usr/local/bin/ruby # This line makes the next one a comment in Ruby \ exec /usr/local/bin/ruby -S $0 $*
$F = $_.splitat beginning of each loop.
% 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
while gets ... end
% echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"' MATZ
#! /usr/local/bin/ruby -s # prints "true" if invoked with `-xyz' switch. print "true\n" if $xyz
On some systems $0 does not always contain the full pathname, so you need the -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(1).