我学习linux的cat命令,我发现这个命令:这个linux命令中的“ - ”是什么意思?
$ echo 'Text through stdin' | cat - file.txt
什么是“ - ”这里的意思?如果我没有输入它,那么'通过标准输入文本'将不会显示。
我学习linux的cat命令,我发现这个命令:这个linux命令中的“ - ”是什么意思?
$ echo 'Text through stdin' | cat - file.txt
什么是“ - ”这里的意思?如果我没有输入它,那么'通过标准输入文本'将不会显示。
通常将stdin
记为短划线(-
)。
甚至man cat
提到:
没有FILE,或者FILE是 - ,读取标准输入。
和手册页甚至有说明使用破折号和普通文件名的例子(这是相当接近你原来的问题,但包括答案):
cat f - g
Output f's contents, then standard input, then g's contents.
认识到'stdin'被读取后文件'file.txt'将被显示是很重要的。 –
@PP。对,我在manpage中添加了两行(顺便说一句,他们是在我原来的引用之后出现的),应该明确这一点。 –
-
讲述了一只猫从读标准输入。如果你通过-
给他们,很多应用程序从标准输入读取这是很常见的。
$ echo 'Text through stdin' | cat - file.txt
-
告诉cat
从标准输入读取,在这种情况下,从管道中,即,什么echo 'Text through stdin'
输出。
可能重复的[是“ - ”意味着标准输出在bash?](http://stackoverflow.com/questions/3797795/does-mean-stdout-in-bash)(无可否认stdin /标准输出,取决于上下文...) – Bruno