Next: 3.8.2 Redirecting input and Up: 3.8 UNIX Plumbing Previous: 3.8 UNIX Plumbing

## 3.8.1 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

`/home/larry/papers# cat history-final masters-thesis`

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.

`/home/larry/papers# cat
Hello there.
Hello there.
Bye.
Bye.
/home/larry/papers#`

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 .

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.

`/home/larry/papers# sort
bananas
carrots
apples
apples
bananas
carrots
/home/larry/papers#`

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

Next: 3.8.2 Redirecting input and Up: 3.8 UNIX Plumbing Previous: 3.8 UNIX Plumbing