在bash脚本中将subshel​​l中的sterr重定向到当前shell中的stdout

Jor*_*kie 2 bash shell scripting io-redirection subshell

我有一个执行功能的子shell:

local thing=$( doFunc )

doFunc将日志输出发送到stderr(2),并且' thing'被分配给(1)doFunc上的输出stdout

如何运行此行,但从stderr子shell 打印到stdout当前shell?

Eri*_*ouf 6

您可以先在另一个FD上复制stdout,然后重定向到类似

exec 3>&1
local thing=$(doFunc 2>&3)
Run Code Online (Sandbox Code Playgroud)