如何查看命令的输出而不是抑制输出

How to sed output of a command and not supress output

我将示例文本存储在 test.sh:

echo 'Hello world 123'
echo 'some other text' 

在 bash 脚本中使用以下命令:

word123=$(./test.sh |sed -nr 's/Hello world (.*)//p' )

这可以正常工作并输出:

123

然而,这确实输出

Hello world 123
some other text

有没有办法捕获 123 中的文本并输出文件中的所有其他内容?

Linuxbashtee:

word123=$( ./test.sh | tee >&255 >(sed -nr 's/Hello world (.*)//p') )

文件描述符 255 是 stdout 的非重定向副本。

参见:What is the use of file descriptor 255 in bash process