From: Eric Christopherson Date: 2013-06-14T08:14:38+09:00 Subject: Re: Unexpected output piping to ruby -pe '' --089e0122ac5066c42404df11342f Content-Type: text/plain; charset=UTF-8 On Thu, Jun 13, 2013 at 4:49 PM, Greg Ferguson wrote: > How come Ruby outputs the incoming piped text when there is no code to > evaluate: > > echo foo | ruby -pe '' > > outputs: "foo" > > Without "-p" there's no output, which I'd expect. Without '' there's an > error, which I'd expect when using the "-e" flag. > > Is there a silent return value of the incoming text that "-p" is then > printing? > Not a return value. From `ruby --help`: -n assume 'while gets(); ... end' loop around your script -p assume loop like -n but print line also like sed So it creates a loop around the (empty) expression; the loop keeps getting the next line from stdin until EOF; and it prints the line. (Actually I believe the line printed is the special variable $_, which gets writes to implicitly. In an actual useful one-liner you would probably filter out certain lines and/or run sub or gsub -- when invoked as Kernel methods, these also implicitly write to $_.) --089e0122ac5066c42404df11342f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, Jun 13, 2013 at 4:49 PM, Greg Ferguson <list= s@ruby-forum.com> wrote:
How come Ruby outputs the incoming piped text when there i= s no code to
evaluate:

=C2=A0 =C2=A0 echo foo | ruby -pe ''

outputs: "foo"

Without "-p" there's no output, which I'd expect. Without= '' there's an
error, which I'd expect when using the "-e" flag.

Is there a silent return value of the incoming text that "-p" is = then
printing?

Not a return value.

From `ruby --help`:
=C2= =A0 -n =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assume 'while ge= ts(); ... end' loop around your script
=C2=A0 -p =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assume= loop like -n but print line also like sed

So it creates a loop around the (empty) expression; the loop keeps= getting the next line from stdin until EOF; and it prints the line. (Actua= lly I believe the line printed is the special variable $_, which gets write= s to implicitly. In an actual useful one-liner you would probably filter ou= t certain lines and/or run sub or gsub -- when invoked as Kernel methods, t= hese =C2=A0also implicitly write to $_.)
--089e0122ac5066c42404df11342f--