21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

260 Chapter 18 ■ Scripting<br />

GNU/Linux. For reasons that we shall shortly see, Unix can act as an excellent basis<br />

<strong>for</strong> scripting.<br />

Unix provides:<br />

■ a textual command language, based on command verbs followed by parameters<br />

■ the facility to write programs in the command language<br />

■ a filing system, with tree-structured directories (folders)<br />

■ a set of useful utility programs, called filters, e.g. a file copy tool<br />

■ a facility, called pipes, <strong>for</strong> joining filters together.<br />

These facilities are now commonly found in many operating systems, but Unix was<br />

the first system to provide them.<br />

Unix consists of a small kernel, augmented by a rich set of small utility programs, the<br />

filters. An example of a filter is a program to display a list of the files within a particular<br />

directory. Perhaps because only two people designed it, Unix is built around a few<br />

simple concepts. One of the fundamental ideas of Unix is the notion that software<br />

(including Unix itself ) should be built from small general-purpose components that are<br />

developed individually. These components can be used individually but also can be<br />

combined as necessary in order to satisfy a new requirement. A filter is a program that<br />

inputs a serial stream of in<strong>for</strong>mation, processes it and outputs a second serial stream.<br />

Other examples of Unix-provided filters:<br />

■ count the number of lines or characters in a file<br />

■ a file copy program<br />

■ print a file with specified <strong>for</strong>matting<br />

■ spool a file to the printer<br />

■ print all lines in a file that contain a specified textual pattern<br />

■ a lexical analyzer.<br />

Filters are combined by taking the output from one and feeding it as input to<br />

another. The stream of data that flows from one filter to another is known as a pipe.<br />

This combination of filters and pipes is carried out by Unix under the control of the<br />

command language.<br />

An example of using a filter is the command:<br />

ls<br />

When you type a Unix command such as this, you invoke the filter with the same<br />

name. The filter named ls displays on the screen the names of all the files in the current<br />

directory, one per line. Another tool, named wc, inputs a file and gives a line, word and<br />

character count <strong>for</strong> that file. The output of wc can be controlled by providing parameters,<br />

and the parameter -l specifies that lines should be counted, so that the command:<br />

wc -l file

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!