I am stuck with the problem. Basically I have two different text files one with questions, another one with answers. Loop reads the first question from the file and waits for input from the user, then compares input with first line in other text file. But it goes thru the whole second file and compares all the lines.
There is a code.
#!/bin/bash
wrong=0
right=0
while IFS='' read -r question || [[ -n "$question" ]];
do
echo "$question"
read input </dev/tty
while IFS='' read -r answer || [[ -n "$answer" ]];
do
if [[ $answer == *"$input"* ]]
then
((right+=1))
else
((wrong+=1))
fi
done < answers.txt
done < file.txt
echo "Wrong answers: $wrong"
echo "Right answers: $right"
What it does at the moment and takes first line from questions, compares with every single line in answers and goes to another question. But I need nested loop only compare with first line and move one to another question and so on.