next up previous contents
Next: Redirecting input and Up: UNIX Plumbing Previous: UNIX Plumbing

Standard input and output

        Many UNIX commands get input from what is known as standard input and send their output to standard output (often abbreviated as ``stdin'' and ``stdout''). Your shell sets things up so that standard input is your keyboard, and standard output is the screen.

Here's an example using the command cat. Normally, cat reads data from all of the filenames given on the command line and sends this data directly to stdout. Therefore, using the command

will display the contents of the file history-final followed by masters-thesis.

However, if no filenames are given to cat as parameters, it instead reads data from stdin, and sends it back to stdout. Here's an example.

    As you can see, each line that the user types (displayed in italics) is immediately echoed back by the cat command. When reading from standard input, commands know that the input is ``finished'' when they receive an EOT (end-of-text) signal. In general, this is generated by pressing ctrl-D.

Here's another example. The command sort reads in lines of text (again, from stdin, unless files are given on the command line), and sends the sorted output to stdout. Try the following.

Now we can alphabetize our shopping list... isn't UNIX useful?



Ross Biro
Tue May 23 13:39:28 PDT 1995