我正在学习linux的cat命令,我找到了这个命令:
$ echo 'Text through stdin' | cat - file.txt
Run Code Online (Sandbox Code Playgroud)
" - "在这里意味着什么?如果我不输入,则不会显示"Text through stdin".
写stdin为dash(-)是很常见的.
甚至man cat提到:
如果没有FILE,或者FILE是 - ,则读取标准输入.
manpage甚至有一个例子说明破折号和普通文件名的使用(这与你原来的问题非常接近,但包括答案):
cat f - g
Output f's contents, then standard input, then g's contents.
Run Code Online (Sandbox Code Playgroud)
-告诉 cat 从 中读取stdin。这是很常见的,如果你传递给它们,很多应用程序都会从标准输入中读取-。
一些应用程序使用-as stdout。
下面是下载 Blender 的示例,我们没有将其写入文件,而是直接将其写入stdout并通过管道传输到 tar,这会在下载过程中动态扩展它。
wget -c https://download.blender.org/source/blender-2.90.1.tar.xz -O - | tar -xzv
Run Code Online (Sandbox Code Playgroud)
这里-O -告诉 wget 直接写入stdout