12.07.2015 Views

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

246CHAPTER 11Automating Tasks with ScriptsLISTING 11.6while do...doneSyntax of a while LoopThe can be any of the string or integer comparisons from Table 11.2. For example,Listing 11.7 shows a while loop that iterates until the INT variable reaches the value of 4.LISTING 11.7#!/bin/bashINT=1while [ $INT -lt 5 ]doecho $INTINT=$((INT+1))doneExample while LoopThe until loop is similar to the while loop except that the code in the loop is executeduntil the test is true. For example, the loop is run until the INT variable reaches the valueof 4 in Listing 11.8.LISTING 11.8#!/bin/bashINT=1until [ $INT -gt 4 ]doecho $INTINT=$((INT+1))doneExample until LoopThe for loop in Bash changes the value of a variable to a defined list of values, one at atime, until the end of the list. Listing 11.9 shows the basic syntax of a for loop.LISTING 11.9for X in ; do...doneSyntax of a for LoopFor example:#!/bin/bashfor X in dog cat mouse ; doecho “$X”done

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!