I want to output some data to a pipe and have the other process do something to the data line by line. Here is a toy example:
mkfifo pipe
cat pipe&
cat >pipe
Now I can enter whatever I want, and after pressing enter I immediately see the same line. But if substitute second pipe with echo
:
mkfifo pipe
cat pipe&
echo "some data" >pipe
The pipe closes after echo
and cat pipe&
finishes so that I cannot pass any more data through the pipe. Is there a way to avoid closing the pipe and the process that receives the data, so that I can pass many lines of data through the pipe from a bash script and have them processed as they arrive?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…