POSIX basics
POSIX -Portable operating system Interface. stdin, stdout, and stderr are three Input/Output standard streams. These values are following
0: stdin
1: stdout
2: stderr
- stdin is the standard input stream. This accepts text as its input.
- stdout is the standard output stream to write the output data.
- stderr is the standard output stream to show error messages.
Pipe
consider the following command.
ls | cat
in this command, the ls output (stdout) is piped into another command(cat).
Redirect
The > redirection symbol works with stdout by default.
1> To stdout redirect. > is shorthand for 1>
2> To stderr redirect
Examples:
Command 1> capture.txt
The above command will save the stdout into the capture.txt file.
Command 2> capture.txt
The above command will save the stderr into the capture.txt file.
Command 1> capture.txt 2> error.txt
The above command will save the stdout in capture.txt and stderr in error.txt file
Command 1> capture.txt 2>&1
The above command will save the stdout and stderr into capture.txt file