Example of using named pipes in Linux Bash

前端 未结 4 541
一向
一向 2020-12-02 05:36

Can someone post a simple example of using named pipes in Bash in Linux?

4条回答
  •  无人及你
    2020-12-02 06:36

    Open two different shells, and leave them side by side. In both, go to the /tmp/ directory:

    cd /tmp/
    

    In the first one type:

    mkfifo myPipe
    echo "IPC_example_between_two_shells">myPipe
    

    In the second one, type:

    while read line; do echo "What has been passed through the pipe is ${line}"; done

    First shell won't give you any prompt back until you execute the second part of the code in the second shell. It's because the fifo read and write is blocking.

    You can also have a look at the FIFO type by doing a ls -al myPipe and see the details of this specific type of file.

    Next step would be to embark the code in a script!

提交回复
热议问题