【发布时间】:2020-11-05 03:26:42
【问题描述】:
我想默认将脚本的所有标准输出写入日志文件,但也想在控制台上显示一些消息。下面是我试过的示例代码。
#!/bin/bash
LOG='output.txt'
exec 3>&1
exec 1>>$LOG
exec 2>>$LOG
echo "This should be written to log"
echo "This should be written to both screen as well as log"|tee -a >&3
这会将This should be written to log 写入日志文件,这很好。
它只在控制台上写入This should be written to both screen as well as log,但我希望它同时写入控制台和日志。
【问题讨论】: