Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

WwWXxX, udp high ports, d-link extract firmware dsl-2750u, wwwwxxxxx.2G, yxxxcom, WWWXXX, ftp://192.168.100.100, wwwxxx 100, www.xxxcon, wwwxxx

Links

XODOX
Impressum

#1: read command not waiting at pause prompt

Posted on 2008-04-21 08:46:37 by Fox

I've shell loop in which I display 10 lines of the file at a time.
I've code line as follows to pause user:
---- My bash under GNU/Linux loop code ---
while read l
do
if [ $c -eq 10 ]
then
c=1 # reset
echo " *** Press [Enter] key to continue ..."
read anyDamkey
fi
echo $l
(( c++ ))
done < $input


I only see message *** Press [Enter] key to continue ... and read
command skips and loop continue while end of file. It appears that \n
from previous echo $line is feeding read command. In others word I'd
like to flush buffer and wait for pause prompt. How do I fix this. I
spend 4 hours but with no luck :(

~~~~~~~
My output
-----------
line 1 to 10
*** Press [Enter] key to continue .. <--- not wating for use input
line 11 to 20
*** Press [Enter] key to continue .. <--- not wating for use input
line 11 to N



TIA

Fox

Report this message

#2: Re: read command not waiting at pause prompt

Posted on 2008-04-21 08:55:32 by Barry Margolin

In article
<1b4253b6-dc95-42bd-ab8f-ec1422ab34b3@n1g2000prb.googlegroups.com>,
Fox <fox@foxmail.in> wrote:

> I've shell loop in which I display 10 lines of the file at a time.
> I've code line as follows to pause user:
> ---- My bash under GNU/Linux loop code ---
> while read l
> do
> if [ $c -eq 10 ]
> then
> c=1 # reset
> echo " *** Press [Enter] key to continue ..."
> read anyDamkey
> fi
> echo $l
> (( c++ ))
> done < $input
>
>
> I only see message *** Press [Enter] key to continue ... and read
> command skips and loop continue while end of file. It appears that \n
> from previous echo $line is feeding read command. In others word I'd
> like to flush buffer and wait for pause prompt. How do I fix this. I
> spend 4 hours but with no luck :(
>
> ~~~~~~~
> My output
> -----------
> line 1 to 10
> *** Press [Enter] key to continue .. <--- not wating for use input
> line 11 to 20
> *** Press [Enter] key to continue .. <--- not wating for use input
> line 11 to N
>
>
>
> TIA
>
> Fox

Standard input is being redirected, so all the read commands within the
while loop read from the file. The redirection doesn't just apply to
the read command on the while statement itself.

If you want to read from the original stdin before the redirection, you
need to save it:

exec 3<&0
while read l
do
...
read -u 3 anyDamkey
...
done < $input

Or if you specifically want to read from the terminal, use

read anyDamkey </dev/tty

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Report this message

#3: Re: read command not waiting at pause prompt

Posted on 2008-04-21 09:06:29 by Bill Marcum

On 2008-04-21, Fox <fox@foxmail.in> wrote:
>
>
> I've shell loop in which I display 10 lines of the file at a time.
> I've code line as follows to pause user:
> ---- My bash under GNU/Linux loop code ---
> while read l
> do
> if [ $c -eq 10 ]
> then
> c=1 # reset
> echo " *** Press [Enter] key to continue ..."
> read anyDamkey
> fi
> echo $l
> (( c++ ))
> done < $input
>
>
> I only see message *** Press [Enter] key to continue ... and read
> command skips and loop continue while end of file. It appears that \n
> from previous echo $line is feeding read command. In others word I'd
> like to flush buffer and wait for pause prompt. How do I fix this. I
> spend 4 hours but with no luck :(
>
By default the read command reads from standard input, which you have
redirected.
Possible solutions are:
read anyDamkey </dev/tty
read anyDamkey <&2

exec 3<&0
while read l
....
read anyDamkey <&3
....
done <$input

exec 3<$input
while read l
....
done <&3

Report this message

#4: Re: read command not waiting at pause prompt

Posted on 2008-04-21 09:35:24 by Stephane CHAZELAS

2008-04-21, 02:55(-04), Barry Margolin:
[...]
> exec 3<&0
> while read l
> do
> ...
> read -u 3 anyDamkey
> ...
> done < $input
[...]

Or, more logically to my mind:

while read <&3 l; do
...
read anyDamLine
...
done 3< "$input"

Note that -u 3 is a ksh extension also found in bash and zsh, I
don't really see the advantage over the standard <&3 (other than
it allows for fds over 9).

--
Stéphane

Report this message

#5: Re: read command not waiting at pause prompt

Posted on 2008-04-21 11:04:30 by Fox

thank for all your input :) it was really hard to find out the
solution just reading man pages.

Report this message

#6: Re: read command not waiting at pause prompt

Posted on 2008-04-22 04:59:40 by Chris Mattern

On 2008-04-21, Fox <fox@foxmail.in> wrote:
> I've shell loop in which I display 10 lines of the file at a time.
> I've code line as follows to pause user:
> ---- My bash under GNU/Linux loop code ---
> while read l
> do
> if [ $c -eq 10 ]
> then
> c=1 # reset
> echo " *** Press [Enter] key to continue ..."
> read anyDamkey
> fi
> echo $l
> (( c++ ))
> done < $input
>
>
> I only see message *** Press [Enter] key to continue ... and read
> command skips and loop continue while end of file. It appears that \n
> from previous echo $line is feeding read command. In others word I'd
> like to flush buffer and wait for pause prompt. How do I fix this. I
> spend 4 hours but with no luck :(
>
> ~~~~~~~
> My output
> -----------
> line 1 to 10
> *** Press [Enter] key to continue .. <--- not wating for use input
> line 11 to 20
> *** Press [Enter] key to continue .. <--- not wating for use input
> line 11 to N
>
>
>
> TIA
>
> Fox

Question...where is "read anyDamnkey" getting its data from?

Hint: What difference is there between "read l" and "read anyDamnkey"?


--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Report this message