We are trying to use the sed command to give back contents from 2 files (file1q and file1a) - a question and answer file.
The question and answer file are the same with numbers on each line:
1
2
3
4
5
6
7
8
9
10
We are trying to echo the result however the sed command is being echo'd and not the result from the sed command
This is our code:
#!/bin/bash
#clear screen
clear
#reset score to 0
score=0
#loop over files to find contents
i=1
while [ $i -le 10 ]
do
question="sed -n $i{p} file1q.txt"
answer="sed -n $i{p} file1a.txt"
if [ question == answer ]
then
echo "Correct"
else
echo "incorrect"
fi
i=$(( $i + 1 ))
done
As you can see i = 1 so sed should be printing line 1 from both files... However, this is what we are getting (using double quotes): output with double quotes for echo
this is what we are getting with single quotes: output with single quotes for echo
this is what we want:
if [[ $question = $answer ]]