开发者

Unix and tee — chain of commands

开发者 https://www.devze.com 2022-12-30 08:45 出处:网络
In a Unix environment, I want to use tee on a chain of commands like so: $ echo 1; echo 2 | tee file 1 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 purposes of this discussion, let's assume I can't break them a开发者_JS百科part and run the commands separately.


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


Try:

 ( echo 1; echo 2 ) | tee file

Without the parentheses, it's getting parsed as:

 echo 1 ; ( echo 2 | tee file )
0

精彩评论

暂无评论...
验证码 换一张
取 消