gpt4 book ai didi

bash - 为什么管道中的重定向在 Bash 和 Zsh 中表现不同?

转载 作者:行者123 更新时间:2023-12-03 20:22:53 24 4
gpt4 key购买 nike

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

bash> echo foo >/dev/null | cat
bash>
zsh> echo foo >/dev/null | cat
foo
zsh>
Bash 符合我的预期;在 Zsh 中,STDOUT 重定向到 /dev/null似乎死而复生。
为什么会有这种差异?在每种情况下发生了什么?

最佳答案

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.

关于bash - 为什么管道中的重定向在 Bash 和 Zsh 中表现不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67549746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com