|
|
How can I read line input in an interactive way?
I am writing an interactive program (in nawk) that needs to read lines
that the user inputs in stdin.
Is there any way to do this in nawk?
I have thought to use the read command, something like:
"read" | getline
But to my surprise Ubuntu does not have the read command, It seems to
be built in the shell so I am using a plan9port implementation. Any
idea?
|
|
0
|
|
|
|
Reply
|
pmarin
|
4/7/2009 11:34:34 AM |
|
In article <4777e2fc-00db-4def-ad68-121248951bc6@j39g2000yqn.googlegroups.com>,
pmarin <pacogeek@gmail.com> wrote:
>I am writing an interactive program (in nawk) that needs to read lines
>that the user inputs in stdin.
>Is there any way to do this in nawk?
>I have thought to use the read command, something like:
> "read" | getline
>But to my surprise Ubuntu does not have the read command, It seems to
>be built in the shell so I am using a plan9port implementation. Any
>idea?
You don't need "read". Just use "getline var".
Notes:
1) The above assumes that you really do want to read from stdin (as
you stated). Usually, when this question comes up, the real
intent is to read from the user, while the main input (stdin) is
coming from somewhere else (a pipe or a file). In that case,
use: getline var < "/dev/tty"
2) You almost certainly want to use "var" with getline (as shown in
my examples), so as not to disturb $0. For more on this, find
and read Ed's "getline: why not" document.
|
|
0
|
|
|
|
Reply
|
gazelle
|
4/7/2009 12:28:16 PM
|
|
On Apr 7, 2:28=A0pm, gaze...@shell.xmission.com (Kenny McCormack) wrote:
> In article <4777e2fc-00db-4def-ad68-121248951...@j39g2000yqn.googlegroups=
..com>,
>
> pmarin =A0<pacog...@gmail.com> wrote:
> >I am writing an interactive program (in nawk) that needs to read lines
> >that the user inputs in stdin.
> >Is there any way to do this in nawk?
> >I have thought to use the read command, something like:
> > =A0 =A0"read" | getline
> >But to my surprise Ubuntu does not have the read command, It seems to
> >be built in the shell so I am using a plan9port implementation. Any
It works, Thanks=A1
> getline var < "/dev/tty"
good to know
> You don't need "read". =A0Just use "getline var".
>
> Notes:
> =A0 =A0 1) The above assumes that you really do want to read from stdin (=
as
> =A0 =A0 =A0 =A0 you stated). =A0Usually, when this question comes up, the=
real
> =A0 =A0 =A0 =A0 intent is to read from the user, while the main input (st=
din) is
> =A0 =A0 =A0 =A0 coming from somewhere else (a pipe or a file). =A0In that=
case,
> =A0 =A0 =A0 =A0 use: getline var < "/dev/tty"
> =A0 =A0 2) You almost certainly want to use "var" with getline (as shown =
in
> =A0 =A0 =A0 =A0 my examples), so as not to disturb $0. =A0For more on thi=
s, find
> =A0 =A0 =A0 =A0 and read Ed's "getline: why not" document.
|
|
0
|
|
|
|
Reply
|
pmarin
|
4/7/2009 12:57:49 PM
|
|
|
2 Replies
311 Views
(page loaded in 0.001 seconds)
|
|
|
|
|
|
|
|
|