5.6. Standard input, output and errors

When using commands in the shell, the shell associates each process with an open file, and references these open files by using numbers called file descriptors. As numbers are not very easy to remember, the shell gives them (file) names as well.

Here are the file descriptors and their more common names.

Files File descriptor
Input file – standard input 0
Output file – standard output 1
Error output file – standard error 2

There are actually 12 file descriptors, but as can be seen from the above table, 0,1, and 2 are reserved for the ‘standard’ input, output and errors. You are free to use descriptors 3 to 9.

5.6.1. Standard input

Standard input is file descriptor ‘0’. This is where input goes into commands, ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.