Interview Prep/Shell Scripting/Arguments, I/O, here-docs, process substitution and subshells

What is process substitution and when do you use it?

IntermediateConceptArguments, I/O, here-docs, process substitution and subshells
Answer

<(cmd) runs cmd and substitutes a path (like /dev/fd/63) from which its output can be read; >(cmd) gives a path that feeds cmd's stdin.

diff <(ssh web1 cat /etc/nginx/nginx.conf) <(ssh web2 cat /etc/nginx/nginx.conf)
comm -13 <(sort expected_users.txt) <(cut -d: -f1 /etc/passwd | sort)
while read -r pod; do ...; done < <(kubectl get pods -o name)   # loop in current shell
exec > >(tee -a "$log") 2>&1                                    # log everything

It is Bash/zsh only. Under sh (dash) you get Syntax error: "(" unexpected.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arguments, I/O, here-docs, process substitution and subshells