抨击将输出重定向到程序 [英] Bashing redirecting output to a program
本文介绍了抨击将输出重定向到程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么不读取文本文件.这里更好的方法是我的代码.我正在尝试使用 for 读取一行,但它似乎不起作用
Why isn't it reading the text file. What's a better way here is my code. I am trying to read a line using for but it doesnt seem to work
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
推荐答案
(( $# == 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
这篇关于抨击将输出重定向到程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文