Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Possible Duplicate:
Is there a way in bash to redirect output and still have it go to stdout?

How would I send /dev/stdin to both /dev/stdout and a $logfile in one command?

One solution would be just to do it once for both:

 cat /dev/stdin > $tempfile;
 cat $tempfile > /dev/stdout;
 cat $tempfile > $logfile;

But that seems bad. Is there a better way?

share|improve this question

marked as duplicate by Michael Mrozek Feb 23 '11 at 15:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I remember this question being ask before. – phunehehe Feb 23 '11 at 12:42
This is a duplicate. This is related. – phunehehe Feb 23 '11 at 12:53
up vote 7 down vote accepted

The command tee is exactly doing this :

cat /dev/stdin | tee $logfile
share|improve this answer

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