PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > read command not waiting at pause prompt
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

read command not waiting at pause prompt

Réponse
 
LinkBack Outils de la discussion
Vieux 21/04/2008, 07h46   #1
Fox
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut read command not waiting at pause prompt

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
  Réponse avec citation
Vieux 21/04/2008, 08h06   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: read command not waiting at pause prompt

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

  Réponse avec citation
Vieux 21/04/2008, 08h35   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: read command not waiting at pause prompt

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
  Réponse avec citation
Vieux 21/04/2008, 10h04   #4
Fox
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: read command not waiting at pause prompt

thank for all your input it was really hard to find out the
solution just reading man pages.
  Réponse avec citation
Vieux 22/04/2008, 03h59   #5
Chris Mattern
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: read command not waiting at pause prompt

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h00.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 6,44755 seconds with 13 queries