tutorials bash

Piping between shells

Create your own bash pipes to send program output between shells, processes and users.

You may already be familiar with the | command commonly used to send the output of one command into another, e.g. cat /var/log/messages | less. Here we create user-defined pipes to carry output between shells or users.

You will need to set appropriate permissions on the pipe file to share data between users. Try chmod 644 fifo_pipe.

Method

First create the pipe through which you'll send the data using the mkfifo command. This refers to the type of buffer you are creating: 'first in first out' i.e. a pipe.

mkfifo ~/fifo_pipe

Open up a new shell - either open a new terminal window or start a new session. Keep your previous one running so you can send the data from there. In the new window enter:

tail -f ~/fifo_pipe

This runs tail (which outputs the end of the buffer) with the -f option to 'follow' output - that is continue outputting what it finds in the fifo pipe.

Return to the original shell session and now enter:

ls >> ~/fifo_pipe

Running this will perform a directory listing of the current directory, outputting the result into the fifo_pipe we previously created. Now switch back to your second session and see the output of ls!

You can send any data output from one process through a pipe in this way.

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
More info Get the book

Downloadable ebook (PDF, ePub) & Complete Source code

To support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount on all books and courses.

[[ activeDiscount.description ]] I'm giving a [[ activeDiscount.discount ]]% discount on all books and courses.