$STDIN, $STDOUT and $STDERR
Pretty much every Linux command implemented uses three basic Input/Output streams -one for input and two for output:
This is the input stream that the command/script will use. It defines where the input should come from. For example, in the command "more oldfile1", $STDIN will be set to the file oldfile1.
Note: the default $STDIN for most functions is the keyboard
This is the output stream that the command/script will use. It defines where the output should go. For example, in the command "cp oldfile1 > newfile", $STDOUT will be set to the file newfile.
Note: the default $STDOUT for most functions is the screen
This is the error message stream that the command/script will use. It defines where any warnings/errors should be sent. For example, in the command "cp oldfile1 newfile 2> myerrors", any errors will be set to the file myerrors.
Note: the default $STDERR for most functions is the screen
Having these three basic streams makes I/O Redirection possible for almost all Linux commands : i.e. the ability to change where the input comes from and the output and errors sent. When using Linux commands (-and especially when combining them), always be aware of the above three streams and what they should be set to. For example, consider this command to search files under the / for the string "abc":
$ grep "abc" /*
/* this is file "abc" */
grep: /lost+found: Permission denied
grep: /root: Permission denied
The $STDIN for this command has been set to all the files in the root directory (/*) but which stream(s) have the screen output come from? Well, it's actually come from two: the first line (valid output) has come from $STDOUT and the second and third lines (error messages) have come from $STDERR.