read from console in ksh

I am stuck with a problem while reading data from a file..

while [ 1 ]
do
read line
#do some operations and if some condition is satisfied, ask the user to enter his choice.
# using the choice continue operations.
done < fileBeingRead.txt

The problem is, when i am inside the while loop, I am not able to read data from the console/terminal. Is there any way to temporarily read data from console? and then continue looping ?

I would go with this:

#! /usr/bin/ksh

exec 5<> /dev/tty

while read line ; do
        print -u5 I just read: $line
        print -u5 -n "continue? "
        read -u5 ans
        print ans = $ans
        if [[ $ans != y* ]] ; then
                print -u5 good-bye
                exit 1
        fi
done < data
exit 0

:slight_smile: Thank you! But is it possible for you to explain me how it works ?

exec 5<> /dev/tty

I can understand that you are setting both input and output to /dev/tty. A little explanation will help me a lot.

thanks!

It's not clear what needs explaining. :confused:

The exec opens fd 5 for i/o to /dev/tty. The read and print statement use this fd via the -u5 argument.

thank you.