我想在bash脚本提供一个可选的日志记录参数,并想用exec给tee管道从一开始。但是,打开tee进程导致脚本挂起,我相信是因为未关闭stdout:
# Output to a log file, if set
if [[ $OPT_LOG ]]; then
exec > >(tee -a $OPT_LOG)
fi
Run Code Online (Sandbox Code Playgroud)
我试图用以下方法结束:
exec >&-
Run Code Online (Sandbox Code Playgroud)
但它仍然挂起-还有另一种方法可以正确关闭,tee以便脚本在执行结束时正确退出吗?