linux - 任何人都可以解释一下这个命令是如何工作的吗?

标签 linux shell unix

当我使用参数将 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/

相关文章:

java - 使用 shell 脚本运行 jar 文件时限制 kill 命令

linux - Shell:将变量插入命令中

linux - 每周为 root 用户脚本更改密码

c++ - "clean"规则在 Makefile 中不存在,但无论如何 make clean 都会产生一些东西

linux - Linux 容器的应用程序隔离?

linux - 制作一个 "copy"的linux系统

bash - 如何在 nounset 时在 shell 中智能附加 LD_LIBRARY_PATH

Linux - 将部分输出重定向到文件

linux - 从 shell 脚本中调用 Curl

java - Bonjour - 适用于 Linux 的 DNS_SD.jar 库?