Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Do someone knows a way to send the stdout of a command both to another command and display it in the shell screen? Note: without using files.

An example (in this case I use wc -l to make it simple )

~> echo "test" | wc -l

but I need to have


I have tried the tee command, expecting it would do it, but it returns the same thing

~> echo "test" | tee | wc -l

Any ideas? Thanks

share|improve this question
up vote 1 down vote accepted

It is really clear how you want the output to be formatted. Even, if you use tee the output will be redirected to wc -l. So, you will not see the output of echo.

I can think of a workaround to send both of echo output and wc -l to the terminal by sending one to stdout and stderr using:

$ echo "test" | tee /dev/stderr | wc -l

This way you will both sent to your terminal via stdout and stderr.

The idea of using named pipes posted by @DukeLion is a nice one also.

share|improve this answer
Perfect! Just enough for my need. Thanks @Khaled – Barooh Jun 7 '12 at 10:53

You can use named pipe with tee to do the trick.

create named pipe: mkfifo /tmp/testpipe

use tee to duplicate output to stdout and pipe: echo "test" | tee /tmp/testpipe

Your command will hang at this moment, since nothing is connected to pipe output. You need to run in different shell cat /tmp/testpipe | wc -l

Named pipe is a file, but it will not do neither disk io nor memory buffering.

share|improve this answer
Thanks @DukeLion, and I have tested it works. You make me discover the named pipes, I will use it in other situations as in this case I must run this into bash script. – Barooh Jun 7 '12 at 10:57
No problem, just run echo "test" | tee /tmp/testpipe in background, like this echo "test" | tee /tmp/testpipe & – DukeLion Jun 7 '12 at 14:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.