From: David Alan Black Date: 2002-07-23T03:27:31+09:00 Subject: Re: piping into ruby at command line Hi -- On Tue, 23 Jul 2002, Dossy wrote: > $ cat >junk.txt < asdf > 1234 > EOT > > $ cat junk.txt | ruby -ne "print $_" > > Strangely, this didn't do what I expected: > > $ cat junk.txt | ruby -ne "puts $_" > > Using #puts, I got two blank lines. This happens in both 1.6.7 and > 1.7.2: > > ruby 1.6.7 (2002-03-19) [i386-linux] > ruby 1.7.2 (2002-05-30) [i686-linux] OK, after some mystification, I figured out what's happening. The shell is interpolating its own $_ -- which is nothing. So what you're really getting is just "print" and "puts". print uses $_ (the Ruby one) by default. puts doesn't. Try putting the inline script in single quotes instead of double, or escape the $ with a \ . David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav