Bash — pipes and redirections
stdin,stdout and stderr
When bash starts creates three file descriptors, these file descriptors point not to a file but in a terminal device usually in the format of /dev/tty[n]
stdin: file descriptor 0, stdin stands for standard input and means incoming to the terminal data, the standard device to enter data to the terminal is the keyboard.
stdout: file descriptor 1, stdout stands for standard output and means printing to the terminal normal messages, or text.
stderr: file descriptor 2, stderr stands for standard error and means printing error messages to the terminal.
redirecting output
The stdout and stderr can redirected to a file if we want, to do this we need to use redirection operators
The >
operator
The >
operator redirects the process output to a file, if the file does not exist will be created, if exists will be overwriten.
command > file.txt
Another way to do this is to write the full version, using the file descriptor
command 1> file.txt
The >>
operator
The >>
operator redirects the process output to a file, if the file does not exist will be created…