我有一個可執行文件,說它叫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