为什么不读取文本文件。这里有一个更好的方法是我的代码。 我正在尝试使用for读取一行,但它似乎无法正常工作
if [[ "$#" -ne 1 ]]
then
writeusage
exit
fi
your_path=../file/test1
test_path=../../public/test1
file_input="$1"
while read -r line
do
args+="$line"
done < "$file_input"
# Redirect the output to a file named text
$test_path > correctanswer 2>&1
# Redirect your output to a file named text2
$your_path > youranswer 2>&1
# diff the solutions
diff correctanswer youranswer
答案 0 :(得分:1)
(( $# == 1 )) || { writeusage; exit 1; }
your_path=../file/test1
test_path=../../public/test1
file_input="$1"
# for bash older than 4.x
while read -r line; do
args+=( "$line" )
done < "$file_input"
## ...for newer bash, you could do this instead:
# readarray -t args <"$file_input"
# Redirect the output to a file named text
"$test_path" "${args[@]}" > correctanswer 2>&1
# Redirect your output to a file named text2
"$your_path" "${args[@]}" > youranswer 2>&1
# diff the solutions
diff correctanswer youranswer
答案 1 :(得分:0)
您需要将for循环更改为:
while read -r line
do
args+="$line"
done < "$FILE_INPUT"