gentooboontoo gentooboontoo - 3 months ago 6x
Bash Question

How to pipe stdout while keeping it on screen ? (and not to a output file)

I would like to pipe standard output of a program while keeping it on screen.

With a simple example (

use here is just for illustration purpose) :

$ echo 'ee' | foo

<- the output I would like to see

I know tee could copy stdout to file but that's not what I want.

$ echo 'ee' | tee output.txt | foo

I tried

$ echo 'ee' | tee /dev/stdout | foo
but it does not work since tee output to
is piped to


Here is a solution that works at on any Unix / Linux implementation, assuming it cares to follow the POSIX standard. It works on some non Unix environments like cygwin too.

echo 'ee' | tee /dev/tty | foo

Reference The Open Group Base Specifications Issue 7 IEEE Std 1003.1, 2013 Edition, ยง10.1:


Associated with the process group of that process, if any. It is useful for programs or shell procedures that wish to be sure of writing messages to or reading data from the terminal no matter how output has been redirected. It can also be used for applications that demand the name of a file for output, when typed output is desired and it is tiresome to find out what terminal is currently in use. In each process, a synonym for the controlling terminal