Note, this is a bash answer, not zsh.
There are cases in bash where you can't use pipes:
some_command | some_other_command
because pipes introduce subshells for each component of the pipeline, when the subshells exit, any side-effects you were relying on would disappear. For example, this contrived example:
cat file | while read line; do ((count++)); done
echo $count
will display a blank line, because the $count
variable does not exist in the current shell.
A bash process substitution allows you to avoid this conundrum by allowing you to read from the "some_command" output like you would from a file
while read line; do ((count++)); done < <(cat file)
# ....................................1.2
echo $count # the variable *does* exist in the current shell
(1) is a normal input redirection. (2) is the start of the <()
process substitution syntax.
This helped me figure out why MacOS
pfctl -f <(echo "pf rules")
would say bad file descriptor. using zsh and =(echo "pf rules") instead works. – johnnyB – 2017-12-20T22:42:56.633Anyone know what this is called or how to do this same thing in fish? I get "invalid redirection target" in fish shell with
<(command)
format. – Elijah Lynn – 2020-02-28T22:50:08.503