Chapter Summary

   

This was the second and last chapter on the topic of shell programming. Shell loops are discussed in this chapter. You started learning arithmetic and logic operations with the help of the let command. Explicit and implicit modes of the let command were discussed. Table 11-1 listed operators that can be used with the let command. Then you studied the while-do-done loop. The syntax of this loop is:

 while condition do    command block done 

The while-do-done loop repeats itself until the condition becomes false. The until-do-done loop is similar to the while-do-done loop; the only difference is that it repeats until the condition becomes true. The syntax of this loop is:

 until condition do    command block done 

Next you studied the for-do-done loop, which is used to process a list of elements provided as the argument to the for command. The syntax of the for-do-done loop is:

 for var in list do    command block done 

The for-do-done loop continues to execute until it has processed all elements in the list. You also found flow diagrams of all these loops in this chapter.

When you need to break a loop, you can use the break , continue , or exit commands. The break command transfers program control to the command just after the next done keyword. The continue command skips all remaining commands in the loop and transfers control to the start of the loop. The exit command permanently terminates the program and returns an exit code. The exit command is used in situations where a critical error is encountered and it is dangerous to continue program execution.

In the last part of the chapter, you learned some text processing commands. The stream editor ( sed ) is used to edit data received at stdin. The edited data is sent to stdout . With the help of shell programs, you can perform some complex editing tasks using sed . The cut command is used to extract data coming from stdin. This command is especially useful when the data are in the form of fields separated by a delimiter . You can extract any field with the help of the cut command by specifying a field number. A small shell program was presented to send mail to all system users with the help of the cut command. The sleep command is used to suspend program execution for a certain amount of time.

This is the last chapter of the first part of the book. The next part contains chapters related to HP-UX system administration. The material presented in the next chapters is specific to HP-UX and may not be used on other UNIX systems.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net