我正在运行一个脚本,使用
tee
命令将输出结果同时显示在屏幕和文件中:{ echo "hello world" ; exit 1; } | tee -a logfile.log
exit
不起作用。我无法退出我的脚本。当我删除tee
时,它可以正常工作。为什么会这样?
{ echo "hello world" ; exit 1; echo xyzzy; }| tee -a logfile.log
,你会发现xyzzy
不会被写入到标准输出或文件中。在像command1 | command2
这样的结构中,每个命令都在自己的子 shell 中执行。(如果启用了lastpipe
选项,则最后一个命令可能在当前 shell 中运行) - M. Nejat Aydin