Bash – Difference between piping and command expansion

bashcommand-substitutionpipe

This link is relevant What's the difference between substitution and piping to bash but I am not quite understanding everything that is being said.

What is the difference between piping command1 | command2 versus expanding commands command2 $(command1)? For example

vi $(find /home | grep xyzzy)

spits results out to vi to edit whereas

find /home | grep xyzzy | vi

doesn't seem to work for me. But I'm not understanding the fundamental difference.

Edit

Other relevant posts

Process substitution and pipe

Process substitution and pipe

Best Answer

A|B

executes A and B (in parallel), and the standard output of A is fed into the standard input of B. In the case of

A $(B)

the shell executes first B, collects the standard output of B, then executes A, but for this execution assigns the individual word's to the ARGV-vector of A (i.e. A can access these words by the usual argv mechanism known from C and other language).

Aside from the fact that in both cases two programs A and B are involved, I don't see anything similar between them.

Related Question