我正在学习linux的cat命令,我发现这个命令:
$ echo 'Text through stdin' | cat - file.txt
这里“ – ”是什么意思? 如果我不input它,那么“通过标准input法的文本”将不会显示。
把stdin
写成短划线( -
)是很常见的。
甚至man cat
提到:
如果没有FILE,或者FILE是 – 读取标准输入。
而手册页甚至有一个例子说明使用破折号和普通文件名(这与你原来的问题非常接近,但包括答案):
cat f - g Output f's contents, then standard input, then g's contents.
-
告诉猫从标准输入读取。 如果你传递给他们,很多应用程序从标准输入读取这是很常见的。
$ echo 'Text through stdin' | cat - file.txt
-
告诉cat
从标准输入读取,在这种情况下,从管道读取,即什么echo 'Text through stdin'
输出。