为什么在Bash和Zsh中管道重定向的行为不同?

4

当Bash和Zsh连接到管道时,重定向会有不同的行为:

bash> echo foo >/dev/null | cat
bash>

zsh> echo foo >/dev/null | cat
foo
zsh>

Bash做我期望的事情; 在Zsh中,被重定向到/dev/null的标准输出似乎又回来了。

为什么会有这种差异?每种情况下都发生了什么?

1个回答

7

Zsh有一个名为multios的花哨功能。如果你关闭它,行为几乎与Bash相同。

% echo a >/dev/null | cat
a
% set +o multios          
% echo a >/dev/null | cat
% 

这个在手册中有如下记录。

Note that a pipe is an implicit redirection; thus[, when multios is on, and it is on by default]

date >foo | cat

writes the date to the file foo, and also pipes it to cat.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接