Re: [問題] 該怎麼設計讓shell script能寫入時間?

看板Linux作者 (lloyd huang)時間16年前 (2010/01/31 12:19), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
time 是個 bash build in function. 所以你用正常的 command 導向 (redirections) 是取不到你要的資料的。 測試如下. lloyd@baby's bottle:$ time ls 1> /dev/null 2> /tmp/log real 0m0.002s user 0m0.000s sys 0m0.000s lloyd@baby's bottle:$ { time ls 1> /dev/null 2> /tmp/elog ; } > /tmp/log real 0m0.004s user 0m0.004s sys 0m0.000s lloyd@baby's bottle:$ { time ls 1> /dev/null 2> /tmp/elog ; } 2> /tmp/log lloyd@baby's bottle:$ cat /tmp/log real 0m0.002s user 0m0.004s sys 0m0.000s 不過你的問題實事上也沒那樣複雜,作法如下 lloyd@baby's bottle:$ cat run.sh #!/bin/bash time ls > /dev/null #> ./run.sh 2> /tmp/log ※ 引述《CrazyRat (瘋老鼠)》之銘言: : 我寫了一個shell script : 大致如下 : #!/bin/sh : time ./test xxxxx > /dev/null : time ./test2 xxxxx > /dev/null : 然後把他存成一個run.sh : 接著執行run.sh : 我希望的結果是 : 把time測出來的時間寫到一個檔案 : 但是似乎失敗了 : run.sh > result(result不會紀錄到任何時間的資料) : 該怎麼寫才正確呢? : 感謝m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.60.21
文章代碼(AID): #1BPGJN-0 (Linux)
文章代碼(AID): #1BPGJN-0 (Linux)