Shell 脚本输出到控制台和登录在同一行?

tom*_*ato 2 unix shell solaris

我能不能把这两行shell脚本剪成一行。

我的两行代码回显相同的字符串,但一行进入控制台,另一行进入日志文件。

echo "Starting scriptr" `date '+%T'`  >> script.log 
echo "Starting script" `date '+%T'`
Run Code Online (Sandbox Code Playgroud)

谢谢

dev*_*ull 5

使用tee

echo "Starting scriptr" `date '+%T'` | tee script.log
Run Code Online (Sandbox Code Playgroud)

为了附加到日志文件,请说tee -a


引用自man tee

   tee - read from standard input and write to standard output and files
Run Code Online (Sandbox Code Playgroud)

  • `tee -a` 用于附加,因为原始脚本使用 `>>` (2认同)