学习shell编程 - 3. 条件,循环语句和布尔操作
#!/bin/sh#if/else语句i=1if [ $i = 1 ] ; then #注意里面的分号 echo howelif [ $i = 2 ] ; then echo are else echo youfi #别忘了这个#if/eles语句的单行写法,注意分号if [ $i = 1 ]; then echo how; else echo are ; fi#bool值判断##用 "test xxx"if test "ab" = "ab"; then echo true ; fi##也可以用 [ ], 注意左括号后面和右括号前面都要有空格if [ "ab" = "ab" ]; then echo true; fi#数字比较if test 3 -gt 2 ; then echo greater ; fi#布尔值操作if [ 3 -gt 2 ] && [ 4 -eq 4 ] ; then echo both true; fi#case语句,类似于java中的switchcase "abc" in abc) echo it is abc ;; # 匹配成功,不会再往下走了 1abc2) echo it includes abc ;; *abc) echo it matches abc pattern ;; hello) echo it is hello;;esac######################################################################while循环x=0while [ $x -lt 10 ]do echo $x x=`expr $x + 1`done#for 循环for F in /home/kent/*do echo $Fdone#break 和 continue也支持,这里就不说了