等同于* input *的`tee`命令? [英] `tee` command equivalent for *input*?

查看:61
本文介绍了等同于* input *的`tee`命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

示例:

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

应生成一个包含内容的文件

should generate a file that has contents

1
2

我尝试过

>  echo 1 && echo 2 > zz.txt

它不起作用。

旁注:我知道我可以将每个命令的输出附加到文件中,但是我想一口气做到这一点(实际上,我想将合并的输出通过管道传输到另一个程序)。

另外,我可以自己滚动,但只要有能力我就懒惰:-)

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 :-)

哦,是的,如果它可以在Windows中运行,那就太好了(尽管我猜想有任何bash / linux风格的解决方案都可以通过UnxUtils / msys / etc来工作)

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)

推荐答案

尝试

( echo 1; echo 2 ) > file.txt

生成一个子shell并在那里执行命令

That spawn a subshell and executes the commands there

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

。那不会产生子shell(最后一个命令后的分号很重要)

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

这篇关于等同于* input *的`tee`命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆