Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Folks,
I have a while loop that is taking input from a filewhile read variable
do
.
.
.
done < filename.txtHowever during the loop I am trying to take some user input
print "....[y/n]" read $var
However the read command takes the input from the input file.
What should I be doing?

exec 3< filename.txt
while read -u3 filevar
do
echo "For $filevar, enter uservar: \c"
read uservar
echo "filevar=$filevar uservar=$uservar"
done

Thanks - worked a treat. Now I just read to nuderstand what exec and read -u does?
Any good reading sources online?

There are a lot of good references for unix in general on this forum. Maybe someone will provide a good reference for this.
For the read command, you can do "man read".
The exec command changes the designated input or output file. For example, you can override the default stdout and stderr destination by putting the following at the start of a script:
exec > myscript.log 2>&1
Now, all stdout and stderr will be sent to myscript.log by default. This is much cleaner and better than a lot of individual redirects throughout your script. And even with this directive in effect, you can still force output to the screen with:
echo 'Enter reply: ' > /dev/tty
For your solution, we force the while-loop to use a non-standard unit# (file#).

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |