shell脚本应用(3)--语法结构
- 判断语句
- 条件判断
test expression
[ expression ]
- 条件表达式中常用的判断
- 数值-eq -ne -gt -lt -ge -le[equal not greater than less]
- 字符串=: != -z -n[长度zero nozero]
- 文件-e -r -w -x -s -d -f -c -b[exist read write execute size directory file char block]
- 语句结构
- if [ $mark -le 80 ]
- then
- echo "Your Grade is Average."
- elif [ $mark -gt 80 -a $mark -le 90 ]
- echo "Your Grade is Good."
- else
- echo "Your Grade is Outstanding."
- fi
- case分支
- 语句结构
- case $choice in
- 1) echo "choice1";;
- 2) echo "choice2";;
- *) echo "out of choice"
- 循环语句
- for循环语句结构
- for val in vals
- do
- ...
- done
- while循环语句结构
- i=0
- while [ $i -le 100 ]
- do
- ...
- ((i=$i+1))
- done