read command in while

hi all
iam not able use read command in the while loop in the following program

while read line
do
echo $line
echo "enter name"
read name
echo "your have entered $name"
done < work.txt
THE READ COMMAND INSIDE THE WHILE LOOP IS NOT WORKING, IS ANY OTHER WAY TO SOLVE THIS PROBLEM

thanks to every one :confused:
Avinash

Since read gets that file work.txt spooled in, it get's it's answers from it. Anyway maybe explain what you want to do - maybe there is an alternative way. I see no useful use :eek: of work.txt in this script.

hi thanks for the reply..
my work is done wit my code. but iam debugging the code.. so i just want to know what is happening in side the while loop one by one ... so that i can make my code efficient...

any way thanks reading and replying to my post... :b:

Hope this helps:

TTY=`tty`

while read line
do
echo $line
echo "enter name"
read name < $TTY
echo "your have entered $name"
done < work.txt

Or just:
TTY=`/dev/tty`

just wanted to add that the reason it's not working is because
you are reading from stdin in 2 places:

while read....

and read...

that's what's causing the problem.

First of all Thanks for all the reply

ill work out with mr angheloko code which he has sent

pls work it out is there any possibilities to read twise stdin .. :smiley:

$ TTY=`/dev/tty`
bash: /dev/tty: Permission denied

I think you meant:

TTY='/dev/tty'

Or

TTY=`tty`