`tee` 命令相当于*输入*?

发布于 2024-07-14 18:01:02 字数 631 浏览 13 评论 0原文

unix tee 命令将标准输入拆分为 stdout 和文件。

我需要的是相反的工作方式,将多个输入合并到一个输出 - 我需要连接两个(或更多)命令的标准输出。
不确定这个应用程序的语义应该是什么 - 让我们假设每个参数都是一个完整的命令。

示例:

>  eet "echo 1" "echo 2" > file.txt

的内容的文件,

1
2

应该生成一个包含我尝试过

>  echo 1 && echo 2 > zz.txt

但它不起作用。

旁注:我知道我可以将每个命令的输出附加到文件中,但我想一次性完成此操作(实际上,我想将合并的输出通过管道传输到另一个程序)。< br> 另外,我可以自己推出,但只要我能负担得起,我就会很懒:-)

哦,是的,如果它能在 Windows 中运行那就太好了(尽管我猜任何 bash/linux-)有风味的解决方案有效,通过 UnxUtils/msys/etc)

The unix tee command splits the standard input to stdout AND a file.

What I need is something that works the other way around, merging several inputs to one output - I need to concatenate the stdout of two (or more) commands.
Not sure what the semantics of this app should be - let's suppose each argument is a complete command.

Example:

>  eet "echo 1" "echo 2" > file.txt

should generate a file that has contents

1
2

I tried

>  echo 1 && echo 2 > zz.txt

It doesn't work.

Side note: I know I could just append the outputs of each command to the file, but I want to do this in one go (actually, I want to pipe the merged outputs to another program).
Also, I could roll my own, but I'm lazy whenever I can afford it :-)

Oh yeah, and it would be nice if it worked in Windows (although I guess any bash/linux-flavored solution works, via UnxUtils/msys/etc)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情绪失控 2024-07-21 18:01:02

尝试

( echo 1; echo 2 ) > file.txt

生成一个子 shell 并执行命令

{ echo 1; echo 2; } > file.txt

,也是可能的。 这不会产生子 shell(最后一个命令后面的分号很重要)

Try

( echo 1; echo 2 ) > file.txt

That spawn a subshell and executes the commands there

{ echo 1; echo 2; } > file.txt

is possible, too. That does not spawn a subshell (the semicolon after the last command is important)

遮了一弯 2024-07-21 18:01:02

我想您想要的是并行运行两个命令,并将两个输出合并到另一个命令。

我会这样做:

( echo 1 & echo 2 ) | cat

其中“echo 1”和“echo 2”是生成输出的命令,“cat”是将接收合并输出的命令。

I guess what you want is to run both commands in parallel, and pipe both outputs merged to another command.

I would do:

( echo 1 & echo 2 ) | cat

Where "echo 1" and "echo 2" are the commands generating the outputs and "cat" is the command that will receive the merged output.

箜明 2024-07-21 18:01:02

回声1> zz.txt && 回声2>> zz.txt

应该可以。 您真正要做的就是依次运行两个命令,其中第一个命令重定向到一个文件,然后,如果成功,您运行另一个命令,将其输出附加到您首先编写的文件的末尾。

echo 1 > zz.txt && echo 2 >> zz.txt

That should work. All you're really doing is running two commands after each other, where the first redirects to a file, and then, if that was successful, you run another command that appends its output to the end of the file you wrote in the first place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文