tags:

views:

50

answers:

2

In a unix environment, I want to use tee on a chain of commands like so

$ echo 1; echo 2 | tee file
1
2

$ cat file
2

Why does file only end up as having the output from the final command?

For the purpopses of this discussion, let's assume I can't break them apart and run the commands seperately.

+4  A: 

It has only the output of the second command, as the semicolon indicates a new statement to the shell.

Just put them into parentheses:

(echo 1; echo 2) | tee file
WhirlWind
+1  A: 

Try :

 ( echo 1; echo2 ) | tee file

without the parends, it's getting parsed as:

 echo 1 ; ( echo 2 | tee file )
Steven D. Majewski