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 purposes of this discussion, let's assume I can't break them apart and run the commands separately.
{ echo 1; echo 2; } | tee file
to get the output into a file. Note that{
has to be separated from the command by a space, and}
must appear where a command could appear (so it is after the second semicolon). The other alternative is always to create a new script containing the two indivisible commands and piping the output of that totee
:conjoined-twin-processes | tee file
. – Stefanstefanac