????linux shell???????????????????????а??????????(if)????????(for??while)????????(case)????????????????????£??????????÷?????
???????shell???????if?÷???
????if????[if/then/elif/else/fi]
????if ???????????
????then
????action
????[elif ????
????action
????else
????action
????]
????fi
???????????????????????????????????ο???linux shell ????????????????????
????shell?????????????????????????з???????????д???????????????“’;”??
?????磺
????[chengmo@centos5 ~]$ a=5;if [[ a -gt 4 ]] ;then echo 'ok';fi;
????ok
?????????(test.sh)
????#!/bin/sh
????scores=40;
????if [[ $scores -gt 90 ]]; then
????echo "very good!";
????elif [[ $scores -gt 80 ]]; then
????echo "good!";
????elif [[ $scores -gt 60 ]]; then
????echo "pass!";
????else
????echo "no pass!";
????fi;

?????????????У?[[]]??[]??test ????????[[]] ????????????????
??????????????(for??while??until?÷?????
????for?????÷???(for/do/done)
??????????
????1.for … in ???
????for ???? in seq?????
????do
????action
????done
?????????seq????? ???????????????for…in ?????????????????????????????
???????(testfor.sh)??
????#!/bin/sh
????for i in $(seq 10); do
????echo $i;
????done;

????seq 10 ???? 1 2 3 ????????10????????????
????2.for((??????????????????))
????for((??????????????????))
????do
????action
????done;
???????(testfor2.sh)??
????#!/bin/sh
????for((i=1;i<=10;i++));do
????echo $i;
????done;

????while???????while/do/done)
????while????
????while ???????
????do
????action
????done;
???????1:
????#!/bin/sh
????i=10;
????while [[ $i -gt 5 ]];do
????echo $i;
????((i--));
????done;
???????н????========================
????sh testwhile1.sh
????10
????9
????8
????7
????6
???????2??(??????????????)
????#!/bin/sh
????while read line;do
????echo $line;
????done < /etc/hosts;
???????н????===================
????sh testwhile2.sh
????# Do not remove the following line?? or various programs
????# that require network functionality will fail.
????127.0.0.1 centos5 localhost.localdomain localhost
????until??????
??????????
????until ????
????do
????action
????done
???????????????????????????????????action.
???????(testuntil.sh)??
????#!/bin/sh
????a=10;
????until [[ $a -lt 0 ]];do
????echo $a;
????((a—));
????done;
?????????
????sh testuntil.sh
????10
????9
????8
????7
????6
????5
????4
????3
????2
????1
????0