1

According process substitution in bash, stdout of one command can be piped into several programs at once using the following template:

echo 'foobar' | tee >(command1) >(command2) | command3

So, you could do:

echo "the fox jumped over the lazy dog" | tee >(grep fox) >(grep jumped)

And get the output of all three commands.

Now I tried storing the output of all these commands, but with no success:

echo "the fox jumped over the lazy dog" | tee >(n1=$(grep fox)) >(n2=$(grep jumped))
echo $n1, $n2

You will see $n1 and $n2 are empty! Why? Is there a way to make this work?

Thank you.

4

1 回答 1

1

出于同样的原因,以下输出bar

$ foo=bar
$ $(foo=quux)
$ echo $foo
bar

子外壳(或在您的情况下完全独立的进程)中的分配不会在父外壳(或完全不相关的外壳)中进行更改。

于 2014-07-28T18:16:24.320 回答