想寫一個有點小複雜的linux script - Linux

By Jack
at 2008-10-08T11:38
at 2008-10-08T11:38
Table of Contents
※ 引述《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,...
: 如此週而復始...
: 請問我該從何下手呢? 感謝不盡.
for((i=1;i<=25;i++))
do
read -p "number A ": A
read -p "number B ": B
read -p "number C ": C
echo "==========================================="
if [ -e "/root/number" ];then
echo "$A $B $C" >> /root/input.list
else
echo "$A $B $C" > /root/input.list
fi
done
~
範例是這樣
請閱讀 read 以及 whie for 的用法
其它自己改
--
: 各位好, 我想寫一個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,...
: 如此週而復始...
: 請問我該從何下手呢? 感謝不盡.
for((i=1;i<=25;i++))
do
read -p "number A ": A
read -p "number B ": B
read -p "number C ": C
echo "==========================================="
if [ -e "/root/number" ];then
echo "$A $B $C" >> /root/input.list
else
echo "$A $B $C" > /root/input.list
fi
done
~
範例是這樣
請閱讀 read 以及 whie for 的用法
其它自己改
--
Tags:
Linux
All Comments

By Agnes
at 2008-10-08T22:40
at 2008-10-08T22:40
Related Posts
想寫一個有點小複雜的linux script

By Madame
at 2008-10-08T09:34
at 2008-10-08T09:34
想寫一個有點小複雜的linux script

By Irma
at 2008-10-08T08:56
at 2008-10-08T08:56
如何調整 webcam 的影像?

By Xanthe
at 2008-10-08T08:16
at 2008-10-08T08:16
想寫一個有點小複雜的linux script

By Frederica
at 2008-10-08T04:47
at 2008-10-08T04:47
Live-USB開機問題

By Jack
at 2008-10-08T01:07
at 2008-10-08T01:07