013147572X_ch02 - Quigley.book Page 33 Wednesday, August...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
33 chapter 2 Shell Programming QuickStart 2.1 Taking a Peek at Shell Scripts If you read, write, or maintain programs, the following samples will give you a quick overview of the construction and style of a shell script and introduce you to some of the constructs and syntax found in these programs. Note: If you are not familiar with pro- gramming, skip this chapter and go to Chapter 3. When you have finished learning how to write scripts, you may want to return to this chapter for a quick reference to refresh your memory. The C shell and TC shell emulate the C language syntax whereas the Bourne shell is based on an older programming language called Algol. The Bash and Korn shells tend to be a combination of both the Bourne and C shells, although these shells originated from the Bourne shell. To illustrate the differences in the shells, four sample programs are provided, one for each shell (the C and TC shells are presented together here). Above each program, a list of basic constructs are described for the shell being examined. 2.2 Sample Scripts: Comparing the Major Shells At the end of each section pertaining to a specific shell, you will find a small program to illustrate how to write a complete script. At first glance, the programs for each shell look very similar. They are. And they all do the same thing. The main difference is the syntax. After you have worked with these shells for some time, you will quickly adapt to the dif- ferences and start formulating your own opinions about which shell is your favorite. A detailed comparison of differences among the C/TC, Bourne, Bash, and Korn shells is found in Appendix B. Quigley.book Page 33 Wednesday, August 25, 2004 11:52 AM
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
34 Chapter 2 • Shell Programming QuickStart Before Getting Started. You must have a good handle on UNIX/Linux commands. If you do not know the basic commands, you cannot do much with shell programming. The next three chapters will teach you how to use some of the major UNIX/Linux com- mands, and Appendix A in the back of the book, gives you a list of the most common commands (also called utilities). The Purpose. The sample scripts provided at the end of each section send a mail mes- sage to a list of users, inviting each of them to a party. The place and time of the party are set in variables. The list of guests is selected from a file called guests . The existence of the guest file is checked and if it does not exist, the program will exit. A list of foods is stored in a word list (array). A loop is used to iterate through the list of guests. Each user will receive an e-mail invitation telling him or her the time and place of the party and asking him or her to bring an item from the food list. A conditional is used to check for a user named root , and if he is on the guest list, he will be excluded; that is, he will not be sent an e-mail invitation. The loop will continue until the guest list is empty. Each time through the loop, a food item is removed from the list, so that each guest will be
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/18/2010 for the course CMPE 102 taught by Professor Chang during the Spring '05 term at San Jose State University .

Page1 / 34

013147572X_ch02 - Quigley.book Page 33 Wednesday, August...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online