我有一个可执行文件,说它叫a.out
。这需要输入的两行的提示后 -如何将bash变量重定向到可执行文件?
> ./a.out
> give me input-1: 0 0 10
> give me input-2: 10 10 5
> this is the output: 20 20 20
我可以存储在一个文件中(input.txt中)的输入,并将其重定向到a.out
,文件看起来像这样 -
0 0 10
10 10 5
,我可以打电话a.out
像 -
> ./a.out < input.txt
> give me input-1: 0 0 10 give me input-2: 10 10 5
> this is the output: 20 20 20
现在我想以这种存储文件多输入重定向到a.out
。该文件将看起来像这样2个输入 -
0 0 10
10 10 5
0 0 20
10 10 6
和我写bash脚本一样 -
exec 5< input.txt
while read line1 <&5; do
read line2 <&5;
./a.out < `printf "$line1\n$line2"` ;
done
它不工作,我该怎么做呢?
这可能有助于更具体地描述你的最终尝试不能正确工作。 (如果没有别的,从一般的高质量问题角度来看)。 – 2014-09-22 17:18:54
使用'printf'%s \ n'“$ line1”“$ line2”''更安全。这样,如果'line1'或'line2'中的任何内容读取为格式字符串,则不会引入错误。 – 2014-09-24 16:30:58