home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 13.9 Send Output Two or More Places with tee Chapter 13
Redirecting Input and Output
Next: 13.11 tpipe-Redirecting stdout to More than One Place
 

13.10 How to tee Several Commands Into One File

The tee (13.9 ) command writes its standard input to a file and writes the same text to its standard output. You might want to collect several commands' output and tee them all to the same file, one after another. The obvious way to do that is with the -a option:

$ some-command

 | tee teefile


$ another-command

 | tee -a teefile


$ a-third-command

 | tee -a teefile

A more efficient way is:


>
 
$ (

some-command


> another-command


> a-third-command

) | tee teefile

The subshell operators (13.7 ) collect the standard output of the three commands. The output all goes to one tee command. The effect is the same - but with two fewer pipes, two fewer tee s, and one more subshell.

Unfortunately, the C shell doesn't make this quite as easy. If you can type all the commands on one line, you can do it this way (the same thing works in the Bourne shell):

% (

command1

; command2

; command3

) | tee teefile

Otherwise, use a semicolon and backslash (;\ ) at the end of each line:

% (

some-command

 ;\


another-command

 ;\


a-third-command

) | tee teefile

- JP


Previous: 13.9 Send Output Two or More Places with tee UNIX Power Tools Next: 13.11 tpipe-Redirecting stdout to More than One Place
13.9 Send Output Two or More Places with tee Book Index 13.11 tpipe-Redirecting stdout to More than One Place

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System