Often times I've noticed on a loop... the read method is kind of... skipped. I'm not sure of the reason for this, or if it's just user error. But I have a work around that I tend to use. I load things into an array. Now I'm sure it has something to do with the text being 'loaded' using the for loop that makes read ignore what it's supposed to do, but this method below works.
[quote=questions.txt]
capital of Hungery? a)budapest b)paris c)pitsburgh d)i dont no :a
The longest river in the world? a)ganga b)nile c)bramhaputra d)dont no :b
Niagara Falls was discovered by? a)jhonny b)Louis Hennepi c)kempson d)adrew heko :b
[/quote]
Code:
#!/bin/bash
correctans=0
wrongans=0
qarray=-1
declare -a questions
until ! read line
do
qarray=$((qarray + 1))
questions[$qarray]=`echo $line`
# qarray=$((qarray + 1))
done < questions.txt
for i in `seq 0 $qarray`
do
echo $i
ans=`echo ${questions[$i]} | cut -d ':' -f2`
echo ${questions[$i]} | cut -d ':' -f1
read -p "Enter Your Answer:" USERANS
# echo $USERANS
sleep 2
if [ "$ans" == "$USERANS" ]
then
correctans=$(( $correctans + 1 ))
fi
# sleep 2
done
echo you answered $correctans correctly
hope that helps