This script:#!/bin/bashtmppipe=/tmp/temppipemkfifo $tmppipeecho test > $tmppipecat $tmppipeexitDoes not terminate. I assume that the cat command is waiting for an EOF from the pipe; how do I send one?
How do I close a FIFO pipe?
pipe;fifo
No, it'secho test > $tmppipe # BTW, you've got the quotes in the wrong placesthat hangs. More precisely, it's the shell opening the pipe for writing before running echo.pipe are inter-process communication mechanisms, they are to be used between processes running concurrently. Here, the open(WR_ONLY) (>) will block until another process does an open in read mode.echo test > $tmppipe &cat < $tmppipewill work because echo and cat run concurrently.On Linux, you can get away with:exec 3<> $tmppipeecho test >&3cat < $tmppipeexec 3<&-That works because read+write opens (<>) on pipes don't block on Linux, and because the test\n output by echo is small enough to fit in the pipe, so you can do the write and the read sequentially.It wouldn't work for a larger output like:exec 3<> $tmppipeseq 100000 >&3cat < $tmppipeexec 3<&-Because seq would fill up the pipe (64kiB in current versions of Linux) and block until some other process reads data off that pipe, which will never happen because cat won't run until seq has finished.Note that:echo test 1<> $tmppipecat < $tmppipewould not work either because the echo command line would open the pipe, write test and then close the pipe (and then the system would destroy it as there's no file descriptor open to it anymore). So the next cat command line would try to instantiate a new pipe (and block until something opens the fifo file for writing).