2013-10-24 96 views
1

我可以將這兩行shell腳本分割成一行。Shell腳本輸出到控制檯並登錄同一行?

我的兩行代碼回顯相同的字符串,但一行進入控制檯,另一行進入日誌文件。

echo "Starting scriptr" `date '+%T'` >> script.log 
echo "Starting script" `date '+%T'` 

感謝

回答

4

使用tee

echo "Starting scriptr" `date '+%T'` | tee script.log 

爲了追加到日誌文件,說三通-a


man tee報價:

tee - read from standard input and write to standard output and files 
+2

'tee -a'用於追加,因爲原始腳本使用'>>' –

+0

感謝您注意到在問題中。 – devnull

+0

感謝您的支持!另外,如果您雙擊.log文件,它將在控制檯中打開。 –