I'm not entirely sure what the flow should look like in your code, so I'll give two versions:
The user guesses until they correctly guess the current word in the file, then moves on to guess the second word, and so on.
The user guesses the current word, and moves on to the next regardless of whether the guess was correct or not.
The first variation:
exec 3<&1
n=0
while read word; do
n=$(( n + 1 ))
while true; do
printf 'Word #%d\n' "$n"
read -p 'guess the word: ' -u 3 guess
if [ "$guess" = "$word" ]; then
echo 'correct'
break
fi
echo 'wrong, try again'
done
done <words
exec 3<&-
We can't just read
inside the loop as that would read from the file. Instead we read from filedescriptor 3, which is a copy of standard input made before the loop. After the loop, this filedescriptor is closed.
The inner while
loop iterates until a correct guess is made.
The second variation:
exec 3<&1
n=0
while read word; do
n=$(( n + 1 ))
printf 'Word #%d\n' "$n"
read -p 'guess the word: ' -u 3 guess
if [ "$guess" = "$word" ]; then
echo 'correct'
else
echo 'wrong, next word...'
fi
done <words
exec 3<&-
This is similar to the previous code, but without the inner while
loop.