請問怎麼在.sh檔裡用time輸出指令的執行時間? - Linux

Table of Contents

小弟如果直接在command line下列指令:
(time ./a.out) >> test.log

可以把執行./a.out的輸出與其執行時間輸出到test.log這個檔

ex.
./a.out會輸出 Hello World
則test.log裡面的內容會是
Hello World
0.000u 0.001s 0:00.00 0.0% 0+0k 0+0io 0pf+0w



但是同樣在run.sh檔中打
(time ./a.out) >> test.log
執行./run.sh後,test.log裡面的內容卻只有
Hello World
執行時間的資訊不會出現在test.log裡面,而是出現在command line上
而且格式變成
real 0m0.004s
user 0m0.001s
sys 0m0.000s



請問我指令要怎麼在run.sh寫,才能讓test.log這個檔裡面有執行時間的資訊
而且格式是
real 0m0.004s
user 0m0.001s
sys 0m0.000s
這樣子呢?


困擾好久了
一直都試不出來 @@
麻煩高手幫幫忙囉
感激呀

--

All Comments

Megan avatarMegan2011-02-16
(time ./a.out) 2>>test.log
Gilbert avatarGilbert2011-02-18
(xxxx) &>>test.log
Madame avatarMadame2011-02-20
dream大的方式變成test.log中只有輸出執行時間的資訊
./a.out的執行內容不會輸出到test.log了 @@
Vanessa avatarVanessa2011-02-25
而k大的指令是syntax error 請問該怎麼寫才對呢?
Zanna avatarZanna2011-03-01
(time ./a.out) >> test.log 2>&1
Kelly avatarKelly2011-03-04
你有沒有多空格之類的?還是你不是用bash? @@
Tom avatarTom2011-03-05
imcar大的方式可以了 感謝
Adele avatarAdele2011-03-06
k大, echo $SHELL 結果是 /bin/tcsh, 所以不是bash?
Lydia avatarLydia2011-03-10
不是XD