UNIX Shell loop control-while LOOP, Syntax: [plain] while command do Statement (s) to be executed if command is true done command can be a judgment, it can also be a command, such as reading files. If the command condition is true, execute the statement block in the loop. Otherwise, exit the loop directly. Www.2cto.com instance 1. A simple while LOOP prints data from 0 to 10: [plain] pg while1.sh #! /Bin/ksh I = 0 while [$ I-le 10] do echo $ I = 'expr $ I + 1' done # EOF execute the script: [plain] sh while1.sh instance 2. I want to move all the files whose names contain if in the current directory to the iftest folder. In this example, a temporary file temp.txt is used to save the file queried from the current folder. After creation, delete the file. [Plain] pg mvfile. sh #! /Bin/ksh echo "moving all file which contain word if to directory iftest" # create temporary file temp.txt if [-f temp.txt]; then ""> temp.txt echo "clearing temp.txt file successful" else touch temp.txt echo "making file temp.txt successfull" fi # writing file temp.txt with file contain word if ls-l | grep '^-. * '| sed-n'/if/'P | awk' {print $9}'> temp.txt # moving file to directory iftest while read LINE do mv $ LINE. /iftest done <temp.txt # droping the temporary file after moving echo "moving file with if successfull" if rm-f temp.txt>/dev/null 2> & 1; then echo "removing file temp.txt successful" fi # EOF before executing this script, the file in the current directory is as follows: www.2cto.com [plain]... /shell> lf calculator. sh ifcp2.sh ifroot. sh param. sh child. sh * ifdirec. sh ifset. sh profile. sh data. file ifeditor. sh iftest/test/elif. sh ifelif. sh iftest2.sh testdirec/env_variable ifels. sh iftst. sh * test1/father. sh * ifinteractive. sh ifwr. sh tst/grepif. sh ifmkdir. sh if1.sh * welcome. sh grepstr. sh ifmkdir2.sh if2.sh 125017.sh ifcounter. sh ifparam. sh log.txt ifcp. sh ifpwd. after sh name.txt is executed, all files containing if are moved to the iftest Directory: www.2cto.com [plain]... /shell/iftest> lf elif. sh ifeditor. sh ifparam. sh ifwr. sh grepif. sh ifelif. sh ifpwd. sh if1.sh * ifcounter. sh ifels. sh ifroot. sh if2.sh ifcp. sh ifinteractive. sh ifset. sh ifcp2.sh ifmkdir. sh iftest2.sh ifdirec. sh ifmkdir2.sh iftst. sh * -- the end --