;; *) (Web server certificate) { body } ;; esac An

;; *) { body } ;; esac An example of the case command follows. This fragment of code sets the TYPE and RCFILE variables based on the user s default shell as reported in the seventh (colon-separated) field of the /etc/passwd file: Shell=`grep “^$USER:” /etc/passwd | awk -F: { print $7 } ` case “$Shell” in /bin/sh) TYPE=Bourne RCFILE=”.profile” ;; /bin/csh) TYPE=C RCFILE=”.cshrc” ;; /bin/bash) TYPE=Bourne RCFILE=”.bashrc” ;; /bin/tcsh) TYPE=C RCFILE=”.tcshrc” ;; *) TYPE=other RCFILE=”unknown” ;; esac The asterisk (*) is used as a catchall. If none of the other entries are matched on the way down the loop, the asterisk is matched and the value is set to unknown. The while . . . do and until . . . do loops Two other possible looping constructs are the while . . . do loop and the until . . . do loop. The structure of each is presented here: while condition until condition do do { body } { body } done done In a while loop, the condition is usually a test statement, but it can also be used to read input until an End-of-File () is encountered. If a test condition is used, the body of the loop is executed until the condition evaluates to false (a return code of 1). A sample is included here: while read COL1 COL2 COL3 COL4 do echo -n ” | X $COL2 | $COL3 ” > /home/ben/DB echo “| $COL4 | $COL1 X |” > /home/ben/DB done This loop reads values (in groups of four) from the keyboard, rearranges the column order, and outputs them to a file in a particular format. The until loop executes the code in the body until the test evaluates to true (a return code of 0). At that point, the loop exits. COUNT=1 until [ $Count -eq 34 ] do DIR=/home/grd/proj/$Count if [ ! -d $DIR ]
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Leave a Reply