I'm reading a book, it says:
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
So basically what this is saying is that standard input is a command that allows user to write to a file, while standard output is a command that has the bash shell write output to the shell, and standard error is just like output but it is only invoked when there is an error in file system. Then we get to the part of connecting STDOUT and STDIN and I'm lost.
<file
is a shorthand for0<file
, so0<file cmd
can be read as: 1. connectfile
to 0/stdin, 2. runcmd
. Correspondingly, for>
, 1/stdout is inferred left of the>
operator if no file descriptor was given there. Hence,cmd >file
is a shorthand forcmd 1>file
which can be read as: 1. connect 1/stdout tofile
, 2. runcmd
. – Carl Sep 10 '22 at 18:41