Reputation: 295
currently I have a file named testcase and inside that file has 5 10 15 14 on line one and 10 13 18 22 on line two
I am trying to bash script to take those two inputs line by line to test into a program. I have the while loop comment out but I feel like that is going in the right direction.
I was also wondering if is possible to know if I diff two files and they are the same return true or something like that because I dont now if [["$youranswer" == "$correctanswer"]]
is working the way I wanted to. I wanted to check if two contents inside the files are the same then do a certain command
#while read -r line
#do
# args+=$"line"
#done < "$file_input"
# Read contents in the file
contents=$(< "$file_input")
# Display output of the test file
"$test_path" $contents > correctanswer 2>&1
# Display output of your file
"$your_path" $contents > youranswer 2>&1
# diff the solutions
if [ "$correctanswer" == "$youranswer" ]
then
echo "The two outputs were exactly the same "
else
echo "$divider"
echo "The two outputs were different "
diff youranswer correctanswer
echo "Do you wish to see the ouputs side-by-side?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "LEFT: Your Output RIGHT: Solution Output"
sleep 1
vimdiff youranswer correctanswer; break;;
No ) exit;;
esac
done
fi
Upvotes: 0
Views: 250
Reputation: 798576
From the diff(1)
man page:
Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.
if diff -q file1 file2 &> /dev/null
echo same
else
echo different
fi
EDIT:
But if you insist on reading from more than one file at a time... don't.
while read -d '\t' correctanswer youranswer
do
...
done < <(paste correctfile yourfile)
Upvotes: 1