Chapter 28 . Programming Environments and (Web server) Interfaces 763
Chapter 28 . Programming Environments and Interfaces 763 The second rule allows you to create chains of commands, each of which uses the output of the previous command as its input. A typical use of this behavior is a command pipeline, such as the following rather contrived example: $ cat /etc/passwd | cut -f 5 -d: | tr [:lower:] [:upper:] | sort | head -5 The first part of the command pipeline, cat /etc/passwd, writes the contents of the /etc/passwd file to standard output. The second part, cut -f 5 -d:, cuts out the fifth field of its standard input (the contents of /etc/passwd), using the colon character (:) as the field delimiter (the fifth field of /etc/passwd is the GECOS or name field). The third part, tr [:lower:] [:upper:], translates all lowercase characters in the standard input to uppercase characters. The next element, sort, performs an alphabetic sort on the first letter of its input before sending the sorted list to standard output. The final component, head -5, displays only the first five lines of its standard input to standard out. The output of this pipeline might resemble: ADM BIN DAEMON GAMES LP The following command pipeline should prove more useful: it e-mails the current uptime and load average to the root user: uptime | mailx -s System Usage root The third rule, keeping programs self-contained, is related to the second. The concept behind it is that programs intended for use in command pipelines should make no assumptions about what their input might look like or do any massaging of the output. Consider the cut command shown in the first command pipeline. It takes arbitrarily formatted input and allows the user to specify on what piece of data to operate (the fifth field in the example, where fields are colon-delimited) and then just displays the requested data on standard output. cut doesn t do any post-processing of the output, allowing the user to do with it as she pleases, probably using another tool. The fourth rule is really more a philosophical observation that you can t really predict all the ways in which your program might be put to use. Indeed, as S.C. Johnson once noted, A successful [software] tool is one that was used to do something undreamed of by its author. The point is that the Linux toolkit, for both developers and end users, is full of small tools and utilities that are building block programs routinely used to create
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.