[BLUG] Bash stdout duplicated to a file

Mark Krenz blug_at_mailman.cs.indiana.edu
Tue, 27 Feb 2007 19:50:02 +0000


  You need the 'tee' command.  It does just that.  The following will
send the output from grep to a file called disabledusers and continue piping
the output to wc:


grep disabled /etc/passwd | tee disabledusers | wc -l



On Tue, Feb 27, 2007 at 07:32:47PM GMT, Chris Colvard [cjcolvar_at_indiana.edu] said the following:
> I should know how to do this, but I'm having trouble getting stdout to 
> go to BOTH stdout and a file in a bash script.
> 
> For example, I have the following script
> >#!/bin/bash
> >
> >exec 3>test.log
> >exec >&3
> >echo "Test"
> This will print "Test" to test.log, but not to stdout.  It seems that 
> stdout is redirected to fd3 instead of being duplicated to fd3.
> Is there a way to print to both stdout and a file at the same time?
> 
> Thanks,
> Chris Colvard
> 
> _______________________________________________
> BLUG mailing list
> BLUG_at_linuxfan.com
> http://mailman.cs.indiana.edu/mailman/listinfo/blug
> 

-- 
Mark Krenz
Bloomington Linux Users Group
http://www.bloomingtonlinux.org/