Functions

As you develop a script, you might find yourself repeating a sequence of lines. An example is a sequence of commands to check for a yes or no response from the user of your script. You might find the same script sequence appearing many times throughout the script.

Let's say the sequence of lines consists of 10 commands. If the sequence needs to be repeated 50 times in a row, it is a candidate to be put in one of the looping constructs discussed in Chapter 6, “Flow Control.”

But what if the 50 times that the sequence of 10 commands is to be repeated turn out to be dispersed randomly over the body of your script? Consider the following:

 Lines Lines Lines (Sequence of 10 commands) Lines Lines (Sequence of 10 commands) Other lines Other ...

Get Korn Shell Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.