This question is from https://mywiki.wooledge.org/ProcessSubstitution
mkfifo /var/tmp/fifo1
mkfifo /var/tmp/fifo2
sort list1 >/var/tmp/fifo1 &
sort list2 >/var/tmp/fifo2 &
diff /var/tmp/fifo1 /var/tmp/fifo2
rm /var/tmp/fifo1 /var/tmp/fifo2
As I understand about named pipes, I'm thinking the following is in effect:
On lines 1-2, we create two named pipes: fifo1 and fifo2.
sort list1 > fifo1 &
and sort list2 > fifo2 &
are trying to write to the named pipes so they are blocked until something reads from them.
Then diff
command that comes afterwards, reads from fifo1 and fifo2. So lines 3-4 are unblocked. Next diff
is executed and the output sent to terminal.
Lastly, we delete named pipes fifo1 and fifo2.
The source says all this is the same as diff <(sort list1) <(sort list2)
.
Is my explanation correct?
Thanks!
diff
expects files, and process substitution allows you to turn the output of the twosort
commands into files.