(在BASH中)我想让一个子shell使用一个非STDOUT非STDERR文件描述符将一些数据传回父shell。我该怎么做?最终我希望将数据保存到父shell的某个变量中。
(
# The following two lines show the behavior of the subshell.
# We cannot change them.
echo "This should go to STDOUT"
echo "This is the data I want to pass to the parent shell" >&3
)
#...
data_from_subshell=... # Somehow assign the value of &3 of the
# subshell to this variable
编辑: 子shell运行一个黑盒程序,向STDOUT和&3写入内容。
/bin/sh
的简单shell中无法工作。 - Jan Hudec