Bash 读取多行以重定向

Bash 读取多行以重定向,bash,scripting,Bash,Scripting,目前我有一个名为testcase的文件,在该文件的第一行和第二行有5 10 15 14 10 13 18 22第二行 我正在尝试bash脚本,以便将这两个输入逐行地带到程序中进行测试。我有一个while循环注释,但我觉得它朝着正确的方向发展。 我还想知道是否有可能知道我区分了两个文件,它们是否相同,返回true或类似的内容,因为我现在不知道[[$youranswer==$correctanswer]]是否按照我想要的方式工作。我想检查文件中的两个内容是否相同,然后执行某个命令 #while re

目前我有一个名为testcase的文件,在该文件的第一行和第二行有5 10 15 14 10 13 18 22第二行

我正在尝试bash脚本,以便将这两个输入逐行地带到程序中进行测试。我有一个while循环注释,但我觉得它朝着正确的方向发展。 我还想知道是否有可能知道我区分了两个文件,它们是否相同,返回true或类似的内容,因为我现在不知道[[$youranswer==$correctanswer]]是否按照我想要的方式工作。我想检查文件中的两个内容是否相同,然后执行某个命令

#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 
从diff1手册页:

退出状态为0 如果输入相同,1个不同,2个故障

编辑:

但是如果你坚持一次读取多个文件。。。不要

while read -d '\t' correctanswer youranswer
do
   ...
done < <(paste correctfile yourfile)

@KRUKUSA:我还想知道是否有可能知道我区分了两个文件,它们是否是相同的返回值true或类似的东西…是的,你是否碰巧知道如何从多行中读取?这个问题是一系列密切相关的问题之一,如果不是重复的问题:。
while read -d '\t' correctanswer youranswer
do
   ...
done < <(paste correctfile yourfile)