I'm trying to figure out what a line means in a bash script file:
mkfifo mypipe
nc -l 12345 < mypipe | /home/myprogram > mypipe
Here's what I understand: nc -l part creates a server-side like behavior on port 12345, which takes in input from mypipe, which pipes that output to a program, which pipes the program output back into mypipe.
My question is firstly is my analysis correct? Second, what exactly is the mkfifo, like what kind of file is it? I also don't understand what nc -l outputs exactly in order to pipe into the myprogram.
Thanks for any help.
< mypipeis largely irrelevant; it does mean there is a program with the FIFO open for reading, so that the open for/home/myprogramreturns, but sincencis reading on the socket and not from its standard input, the FIFO will eventually fill (maybe after as little as about 4 KiB of data), blocking/home/myprogram, and thereafter blockingnctoo (another 4 KiB or so, which is the capacity of the pipe), which then blocks whatever process is writing to port 12345.ncreads from both the socket and stdin, and passes the socket input to stdout and stdin input to the socket. You can test it yourself -echo "GET /" | nc www.google.com 80will passGET /to Google's server, and pass its response to your screen.ncdoes, then. It is nominallynetcat, butcatdoesn't read its standard input if it is given a file to read instead (and I assumed that-l 12345meant listen on port 12345 andcatanything that comes in). Ifncis different, so be it; I haven't used it more than once or twice - and that extremely casually. Treat my previous comments with an appropriate pinch of salt (possibly quite large). It is an unusual arrangement of I/O, regardless of whatncdoes; it would be interesting to know what/home/myprogramdoes with its standard input.