Chapter Summary

   

This was an introductory chapter on shell programming, where you studied what a shell program looks like and how to write shell programs. The first line of the shell script is used to determine which subshell will be invoked for the execution of the program. Comments are used in the shell programs with the help of the " # " character, such that anything that follows this character is considered a comment. Then you learned how to debug a program using the -x option. Next was the use of variables in shell programs. Environment variables can be read in a shell program. Any change to environment variables is lost as soon as the program finishes its execution.

Command line arguments are stored in special variables whose names range from $0 to $9 . Above $9 , use braces to enclose the argument number. For example, ${12} would be the twelfth command line argument. The $0 variable shows the name of the program itself, and the rest keep values of other command line parameters. These command line parameters can be shifted left with the use of the shift command.

Interactive programs can be written with the help of the read command. This command takes input from the user at run time and stores it in a variable. The echo command is used to print something on the user terminal. It uses escape characters to format the printed data. You learned about the exit command and exit codes that show termination status of a program.

To make a conditional branch, you need to test a condition. The test command is used for this purpose, and you learned implicit and explicit use of this command. In the last part of the chapter, three branch structures were presented. The first one was the if-then-fi structure, the second was the if-then-else-fi structure, and the third one was the case structure. The if-then-fi structure is used for executing a block of commands if the result of a test is true. Its syntax is as shown here.

 if  expr  then  action  fi 

The if-then-else-fi structure is used to make either one or the other choice of the two available options. Its syntax is:

 if  expr  then    action1 else  action2  fi 

The case structure is used to select one of many options available. The general format of the case structure is:

 case  var  in    pattern 1)       commands       ;;    pattern 2)       commands       ;;    ...    pattern n)       commands       ;;    *)       commands       ;; esac 

In the next chapter, you will learn about use of loops and some more features of shell programming.


   
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