当我使用参数将 stdin 重定向到 tee 命令时,它会显示字符串两次。
$ echo who is this | tee -
who is this
who is this
最佳答案
嗯,tee
的联机帮助页说
Copy standard input to each FILE, and also to standard output.
是的,所以它接受标准输入,即这是谁\n
,并将其复制到标准输出。这将使 who is this\n
在您的终端上可见一次。此外,它还会将输入复制到名为 -
的文件中。在 BSD 上,这将创建一个名为 -
的文件并将输入复制到其中。然而,GNU tee 将 -
解释为标准输出,这是一种常见的做法。因此,它会再次将其复制到标准输出。
在 BSD 和 Linux 上运行的版本是
$ echo who is this | tee /dev/stdout
who is this
who is this
您还可以让它打印字符串四次:
$ echo who is this | tee /dev/stdout /dev/stdout /dev/stdout # on Linux alternatively: tee - - -
who is this
who is this
who is this
who is this
关于linux - 任何人都可以解释一下这个命令是如何工作的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36635855/