I am fairly new to bash scripting and a part I am stuck on is after
done< "$file_input"
What I am trying to achieve is when I run the program ./test inside the testfile contains
the numbers 15 14 90 22 and the program is going to take those numbers as the arguments and run it, but I am quite unsure how to do that. Am I going in the correct direction?
Thanks for any help
if [[ "$#" -ne 1 ]]
then
writeusage
exit
fi
your_path=../file/test
test_path=../../public/test
file_input="$1"
while read -r line
do
args+="$line"
done < "$file_input"
----------------- unsure how to redirect the arguments in a text file into my program and then put the result in a file named correctanswer and diff them
# 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
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"))
来源:https://stackoverflow.com/questions/23280857/redirecting-arguments-into-a-program-bash