Redirecting arguments into a program (BASH)

醉酒当歌 提交于 2019-11-29 17:47:36

You can use $(< file) to read a file into a variable. Using it unquoted afterwards will cause the contents to be passed as multiple arguments.

your_path=../file/test
test_path=../../public/test
file_input="$1"
contents=$(< "$file_input")

"$test_path" $contents > correctanswer 2>&1
"$your_path" $contents > youransweranswer 2>&1

diff correctanswer youranswer

This can more succinctly be written using process substitution:

diff <(../../public/test $(< "$1")) <(../file/test $(< "$1"))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!