I'm trying to write a command that can simultaneously (i) read from stdin and (ii) read from a pipe. This basic concept works in
zsh, but not in
bash. The following session illustrates the difference in behavior for the two shells:
$ echo bar > bar $ zsh -f zsh-5.8$ echo foo | cat < bar foo bar zsh-5.8$ exit $ bash --noprofile --norc bash-5.0$ echo foo | cat < bar bar
I can see that the above commands give
cat two sources of stdin (the pipe and the redirect), so perhaps it's ambiguous how that should be handled.
zsh seems to concatenate the two input streams, with the piped input consistently coming first.
bash seems to simply drop the piped input.
My questions are:
- Why do the two shells behave differently?
- Is there any way to force
bashto behave like