|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
thank for all your input
it was really hard to find out thesolution just reading man pages. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|