#! /bin/sh
#simple if useage.
if [ $1 -gt 15 ]; then
echo ">15"
else
echo "<=15"
fi
if … elif…elif…else…
#! /bin/sh
score=$1if[$score -ge 0 -a $score -lt 60 ];thenecho"sorry,you are lost!"elif[$score -ge 60 -a $score -lt 85 ];thenecho"just soso!"elif[$score -le 100 -a $score -ge 85 ];thenecho"good job!"elseecho"input score is wrong , the range is [0-100]!"fi
#! /bin/sh# test if useage.if[$1 -gt 15 -a $2 -eq 15 ];then#[ condition ] condition和[ ] 要有空格分隔。echo">=15"elif[$1 -gt 10 ];thenecho">10"elseecho"else"fi
2. 循环
for 循环
#! /bin/sh#test use for useage. #description: 获取当前目录下, 所有文件以.sh结尾的文件.for shellFile in`find. -iname "*.sh"`doecho$shellFiledone
while循环(只要条件成立,就一直执行)
#! /bin/sh#test while useage. loop number to file.
NUM=$1# loop number.
FILE_NAME=$2#loop number to this file.declare -i ITEM=1 #declare integer number.while[$ITEM -ne $NUM]doecho"->${ITEM}">>$FILE_NAME
ITEM=$ITEM+1
done
until循环(只要条件不成立,就一直执行;直到条件符合)
#! /bin/sh# test util useage. echo number show screen.
NUM=$1declare -i ITEM=1
until[$ITEM -eq $NUM]doecho"hello: $ITEM"
ITEM=$ITEM+1
done