所以基本上这是在说标准输入是一个命令,允许用户写入文件,而标准输出是一个命令,让bash shell将输出写入shell,而标准错误就像输出一样,但只有在文件系统出现错误时才会调用。然后我们来到连接STDOUT和STDIN的部分,我迷失了。Every process has at least three communication channels available to it: “standard input” (STDIN), “standard output” (STDOUT), and “standard error” (STDERR).
Most commands accept their input from STDIN and write their output to STDOUT. They write error messages to STDERR. This convention lets you string commands together like building blocks to create composite pipelines.
The shell interprets the symbols
<
,>
, and>>
as instructions to reroute a command’s input or output to or from a file.To connect the STDOUT of one command to the STDIN of another, use the
|
symbol, commonly known as a pipe.ps -ef | grep httpd
<file
是0<file
的简写,所以0<file cmd
可以理解为:1. 连接file
到 0/stdin,2. 执行cmd
。相应地,对于>
,如果没有在>
运算符左边给出文件描述符,则推断为 1/stdout。因此,cmd >file
是cmd 1>file
的简写,可以理解为:1. 连接 1/stdout 到file
,2. 执行cmd
。 - Carl