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.
The tee command, used with a pipe, reads standard input, then writes the output of a program to standard output and simultaneously copies it into the specified file or files. Use the tee command to view your output immediately and at the same time, store it for future use.
The tee command is normally used to split the output of a program so that it can be both displayed and saved in a file. The command can be used to capture intermediate output before the data is altered by another command or program. The tee command reads standard input, then writes its content to standard output.
What Does tee Command Do in Linux? The tee command reads standard input (stdin) and writes it to both standard output (stdout) and one or more files. tee is usually part of a pipeline, and any number of commands can precede or follow it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With