Forum: Ruby How to exit from the forever loop when using "-np" switch ?

Posted by Love U Ruby (my-ruby)
on 2013-02-13 16:55
I was trying to see the how they(-n,-p) works in ruby?

I tried the below :

peter@ubuntu:~$ ruby -np
"hi"




^Z
[2]+  Stopped                 ruby -np
peter@ubuntu:~$

But the above code taking me to an infinite loop. So my pain point is
how to see that two options functionality?

Thanks
Posted by Robert Klemme (robert_k78)
on 2013-02-13 17:24
(Received via mailing list)
On Wed, Feb 13, 2013 at 4:55 PM, Love U Ruby <lists@ruby-forum.com> 
wrote:
> I was trying to see the how they(-n,-p) works in ruby?

It will read until EOF.

Cheers

robert
Posted by Love U Ruby (my-ruby)
on 2013-02-13 17:30
Robert Klemme wrote in post #1096696:
> On Wed, Feb 13, 2013 at 4:55 PM, Love U Ruby <lists@ruby-forum.com>
> wrote:
>> I was trying to see the how they(-n,-p) works in ruby?
>
> It will read until EOF.
>
> Cheers
>
> robert

I didn't undersatnd, I mean how to return from here. It continues to the 
next line for my every "ENTER"

Thanks
Posted by Robert Klemme (robert_k78)
on 2013-02-13 17:54
(Received via mailing list)
On Wed, Feb 13, 2013 at 5:30 PM, Love U Ruby <lists@ruby-forum.com> 
wrote:
>
> I didn't undersatnd, I mean how to return from here. It continues to the
> next line for my every "ENTER"

"Input from a terminal never really 'ends' [...]"

http://en.wikipedia.org/wiki/End-of-file


Cheers

robert
Posted by Love U Ruby (my-ruby)
on 2013-02-13 17:56
Robert Klemme wrote in post #1096709:
> On Wed, Feb 13, 2013 at 5:30 PM, Love U Ruby <lists@ruby-forum.com>
> wrote:
>>
>> I didn't undersatnd, I mean how to return from here. It continues to the
>> next line for my every "ENTER"
>
> "Input from a terminal never really 'ends' [...]"
>
> http://en.wikipedia.org/wiki/End-of-file
>
>

Okay! So any other way to test such -n -p options?

Thanks
Posted by Love U Ruby (my-ruby)
on 2013-02-13 20:45
`-p` ==> assume loop like -n but print line also like sed.

Now I tried below to see how it works :


    @ubuntu:~$ ruby -p
    hi

    \t
    -:5: syntax error, unexpected $undefined, expecting $end
    @ubuntu:~$

In the above after typing "hi", when I press 'ENTER' got ***blank 
line*** as above. I thought it would give a output as ***hi***.

Now I tried it a bit different way :

    @ubuntu:~$ ruby -p -e '"hi"'
    hi
    hi
    ttt
    ttt
    \t
    \t

But here it seems `-p` worked as expected. But the `Loop` falls into an 
infinite `Loop`.

Can anyone help me to understand why these difference?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.