[問題] 請問怎麼在.sh檔裡用time輸出指令的執꘠…

看板Linux作者 (123)時間13年前 (2011/02/16 04:08), 編輯推噓1(109)
留言10則, 4人參與, 最新討論串1/1
小弟如果直接在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 這樣子呢? 困擾好久了 一直都試不出來 @@ 麻煩高手幫幫忙囉 感激呀 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.195.29.203

02/16 05:54, , 1F
(time ./a.out) 2>>test.log
02/16 05:54, 1F

02/16 08:53, , 2F
(xxxx) &>>test.log
02/16 08:53, 2F

02/16 10:51, , 3F
dream大的方式變成test.log中只有輸出執行時間的資訊
02/16 10:51, 3F

02/16 10:51, , 4F
./a.out的執行內容不會輸出到test.log了 @@
02/16 10:51, 4F
※ 編輯: Hyozero 來自: 123.195.29.203 (02/16 10:52)

02/16 10:52, , 5F
而k大的指令是syntax error 請問該怎麼寫才對呢?
02/16 10:52, 5F

02/16 12:25, , 6F
(time ./a.out) >> test.log 2>&1
02/16 12:25, 6F

02/16 12:26, , 7F
你有沒有多空格之類的?還是你不是用bash? @@
02/16 12:26, 7F

02/16 13:50, , 8F
imcar大的方式可以了 感謝
02/16 13:50, 8F

02/16 13:51, , 9F
k大, echo $SHELL 結果是 /bin/tcsh, 所以不是bash?
02/16 13:51, 9F

02/18 09:34, , 10F
不是XD
02/18 09:34, 10F
文章代碼(AID): #1DMjqcHy (Linux)