Re: [問題] 想寫一個有點小複雜的linux script
※ 引述《mystea (mystea)》之銘言:
: 各位好, 我想寫一個bash script來重複跑一個叫做(./program)的程式.
: ./program 本身會從一個叫做 input.txt 的檔案讀取輸入資料(三個浮點數),
: 然後進行運算產生結果.
: 寫script的目的是要讓電腦自動去讀不同的輸入資料.
: 比方說我總共要跑(./program) 25次. 第一次要輸入1.0 3.5 4.2,
: 第二次要輸入6.8 7.1 5.3,....這樣.
: 這些不同的輸入值被存在另一個檔案input.list裡:
: #start of input.list:
: 1.0 3.5 4.2
: 6.8 7.1 5.3
: ...
: ...
: ...
: (共25行)
: #end of input.list
: 所以跑第一次的時候, 我要先讓bash script讀input.list的第一行,
: 然後把第一行的結果存成input.txt, 然後執行./program
: 執行完./program之後, 把input.txt洗掉, 進行第二個迴圈. 第二個
: 迴圈要把input.list的第二行存成input.txt然後執行./program,...
: 如此週而復始...
: 請問我該從何下手呢? 感謝不盡.
#!/bin/bash
while read line
do
echo $line > "input.txt"
./program
done < "input.list"
不過為啥不讓program吃stdin就好了? 這樣一直存取file很慢耶
--
http://nigel.twbbs.org
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 76.173.13.240
討論串 (同標題文章)