Redirection behaves differently in Bash and Zsh when hooked up to a pipe:
bash> echo foo >/dev/null | cat
bash>
zsh> echo foo >/dev/null | cat
foo
zsh>
Bash does what I expect; in Zsh, the STDOUT redirected to /dev/null
seems to come back from the dead.
Why this difference? What's going on in each case?
Zsh has a fancy feature called multios. If you turn it off, the behavior will be almost identical to Bash.
% echo a >/dev/null | cat
a
% set +o multios
% echo a >/dev/null | cat
%
And this is documented in the manual as follows.
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 tocat
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With