shell脚本应用(3)--语法结构

 

  1. 判断语句
  • 条件判断
test expression
[ expression ]
  • 条件表达式中常用的判断
  1. 数值-eq -ne -gt -lt -ge -le[equal not greater than less]
  2. 字符串=: != -z -n[长度zero nozero]
  3. 文件-e -r -w -x -s -d -f -c -b[exist read write execute size directory file char block]
  • 语句结构
  1. if [ $mark -le 80 ]
  2. then
  3. echo "Your Grade is Average."
  4. elif [ $mark -gt 80 -a $mark -le 90 ]
  5. echo "Your Grade is Good."
  6. else
  7. echo "Your Grade is Outstanding."
  8. fi
 
  1. case分支
  • 语句结构

 

  1. case $choice in
  2. 1) echo "choice1";;
  3. 2) echo "choice2";;
  4. *) echo "out of choice"

 

 
  1. 循环语句
  • for循环语句结构
  1. for val in vals
  2. do
  3. ...
  4. done
  • while循环语句结构
  1. i=0
  2. while [ $i -le 100 ]
  3. do
  4. ...
  5. ((i=$i+1))
  6. done

 

 

posted on 2014-02-26 16:11  飘移  阅读(183)  评论(0编辑  收藏  举报

导航