2

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

3
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.

  • In what shell are piped commands run in parallel? How could that even occur? B has to read A's output (as B's input), which, as far as I'm aware, means A needs to produce an output before B can read it. Additionally, the line that could produce similar behavior using command substitution would be: B $(A), not A $(B), which is the OPs question. – De Novo Jan 28 at 19:24
  • @DeNovo : If you have pipe A|B, the usual implementation is to start both processes A and B, and feed the stdout of A to the stdin of B. Without this, a construct such as A|tail -f would not work. – user1934428 Jan 29 at 10:09
0

The first expands to vi <list_of_filenames>.

The second directly pipes the filenames to vi. Presumably, vi won't work like this. You can certainly pipe text to vim, but that is interpreted as the text to process, not the filename itself. (You's have to use vim -. See man vim for more information.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.