home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 1.2 Who Listens to What You Type? Chapter 1
Introduction
Next: 1.4 Using Pipes to Create a New Tool
 

1.3 Programs Are Designed to Work Together

As pointed out by Kernighan and Pike in their classic book, The UNIX Programming Environment , there are a number of principles that distinguish the UNIX environment. One key concept is that programs are tools. And like all good tools, they should be specific in function, but usable for many different purposes.

In order for programs to become general-purpose tools, they must be data-independent. This means three things:

  1. Within limits, the output of any program should be usable as the input to another.

  2. All of the information needed by a program should either be contained in the data stream passed to it or specified on the command line. A program should not prompt for input or do unnecessary formatting of output. In most cases, this means that UNIX programs work with plain text files that don't contain "non-printable" or "control" characters.

  3. If no arguments are given, a program should read the standard input (usually the terminal keyboard) and write the standard output (usually the terminal screen).

Programs that can be used in this way are often called filters .

One of the most important consequences of these guidelines is that programs can be strung together in "pipelines" in which the output of one program is used as the input of another. A vertical bar ( | ) represents the pipe ( 1.4 ) : it means "take the output of the program on the left and feed it into the program on the right."

For example, you can pipe the output of a search program to another program that sorts the output, and then pipe the result to the printer program or redirect it to a file ( 13.1 ) .

- TOR


Previous: 1.2 Who Listens to What You Type? UNIX Power Tools Next: 1.4 Using Pipes to Create a New Tool
1.2 Who Listens to What You Type? Book Index 1.4 Using Pipes to Create a New Tool

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System