The pipe symbol in bash does not matter esle, and then connects the output of the first command to the input of the second. echo "123" | cat echo "123" | cat essentially coincides with cat < <(echo 123) (the latter only launches one subshell, although at first one for each command is launched, but here it can be ignored - plus, this is a bugism and does not work in sh ).
$ mkfifo foo $ cat foo
Really blocks - but does not freeze. The moment that any other program writes to foo , cat will display it.
What you do in your call netcat essentially creates cicrle: everything written in FIFO will be displayed on cat , and as cat connected to sh sent last. sh then execute the code (since sh will just execute something written on it, an input stream) and send the output to nc . nc will send it to the client. Everything that the client sends to nc is recorded in FIFO - and our circle is completed.
The mistake you made (I think) is to assume that the second pipe process only reads data once, and not continuously, and therefore must wait for the completion of the first process. This is not true because every process in the pipeline runs in shubshell, so they all work independently of each other.
You should also be able to reorder all the commands in your pipeline. While the former is reading from FIFO, and the latter is writing to him (to complete the lap), he should work.
source share