Grep变成变量并保持stdout?

问题描述:

我的流程很长,我想从大量的输出中捕获一小部分数据.

I've got a long running process and I want to capture a tiny bit of data from the big swath of output.

我可以通过grep传递它来执行此操作,但是然后我看不到它会喷出所有其他信息.

I can do this by piping it through grep, but then I can't watch it spew out all the other info.

我基本上希望grep将找到的内容保存到变量中,而不要将stdout保留下来.我该怎么办?

I basically want grep to save what it finds into a variable and leave stdout alone. How can I do that?

使用过程替换 I/O重定向:

{ var=$(cmd | tee >(grep regexp) >&3); } 3>&1