我想拆分,stdout以便打印到stdout和stderr.这听起来像是一份工作,tee但语法却在逃避我 -
./script.sh | tee stderr
Run Code Online (Sandbox Code Playgroud)
当然,stderr这里应该如何引用?
bri*_*gge 50
我发现唯一可以在交互式和非交互式shell中工作的跨平台方法是:
command | tee >(cat 1>&2)
Run Code Online (Sandbox Code Playgroud)
tee的参数是文件或文件句柄.使用进程替换,我们将输出发送到进程.在process = cat =中,我们将stdout重定向到stderr.shell(bash/ksh)负责设置1和2文件描述符.
Nic*_*son 36
./script.sh | tee /dev/fd/2
Run Code Online (Sandbox Code Playgroud)
请注意,这取决于操作系统支持,而不是tee中的任何内置电源,因此不是通用的(但可以在MacOS,Linux,Solaris,FreeBSD,可能还有其他工作).