tee
和过程替代。
让我们从示例开始:
$ head *.sh
文件
一.sh
#!/bin/bash
echo "one starts"
if [ -p /dev/stdin ]; then
echo "$(cat /dev/stdin) from one"
else
echo "no stdin"
fi
二.sh
#!/bin/bash
echo "two starts"
if [ -p /dev/stdin ]; then
echo "$(cat /dev/stdin) from two"
else
echo "no stdin"
fi
文件
#!/bin/bash
echo "three starts"
if [ -p /dev/stdin ]; then
sed 's/^/stdin for three: /' /dev/stdin
else
echo "no stdin"
fi
1:
echo "hello" | tee >(./one.sh) >(./two.sh) | ./three.sh
2:
echo "hello" | tee >(./one.sh) >(./two.sh) >(./three.sh) >/dev/null
zsh
).
Bash(GNU Bash,版本5.0.17(1))
$ echo "hello" | tee >(./one.sh) >(./two.sh) |./three.sh
three starts
stdin for three: hello
stdin for three: one starts
stdin for three: two starts
stdin for three: hello from two
stdin for three: hello from one
-
一.sh
和
二.sh
混合源代码“hello”并传递给
? 我希望在标准输出中看到1和2的输出,只有
"hello"
.
$ echo "hello" | tee >(./one.sh) >(./two.sh) >(./three.sh) >/dev/null
one starts
two starts
three starts
stdin for three: hello
hello from two
hello from one
<---!!!note here I don't have prompt unless I press Enter or Ctrl-c)
-
我将所有标准输出重定向到
/偏差/空
-
-
为什么命令按顺序一开始->二->三个,但输出为3->2->1.即使我添加了
sleep 3
在里面
,
两个命令,
echo "hello" | tee >(./one.sh) >(./two.sh) >(./three.sh) >/dev/null
echo "hello" | tee >(./one.sh) >(./two.sh) |./three.sh
给出预期结果:
one starts
three starts
two starts
hello from two
hello from one
stdin for three: hello