1. 條件測試命令: test or [
            邏輯判斷跟普通的相反,當(dāng)條件為真時(shí),返回0,否則返回1.
          number=2
          test $number -gt 1
          echo $?
          0

          [ $number -gt 3 ]
          echo $?
          1

          note: [ ] 是個(gè)命令,括號(hào)中間是參數(shù),命令和參數(shù)之間要有空格。
          常見的測試命令:
          [ -d dir ]
          [-f file ]
          [-z string ]   String 長度為0時(shí)為真
          [ -n string ]  String 長度非0時(shí)為真
          [arg1 op arg2 ]  op: -eq, -ne, -lt, -gt, -ge, -le

          [ expr1 -a|-o expr2 ] -a=&&  -o=||
           
          2. if/then

          if [ -d tmp ] ; then
             echo "tmp is a directory"
          fi

          這里有三條命令, if [-d tmp ] 是第一條,then是的而條,fi是第三條。兩條命令在一行上,必須用;隔開。如果then令起一行,則不用分號(hào)。

          3. && ||
          shell中的&&相當(dāng)于 if..then.., ||則相當(dāng)于if not ... then...,
          上面的if/then語句也可寫成 [ -d tmp ] && echo "tmp is a directory"

          4. case
          shell的case不僅能匹配整形和字符型,還能匹配字符串和wildcard, 每條分支必須以;;結(jié)束, 不需要break語句跳出。
          echo "input your choice:"
          read choice
          case $choice in
          Yes|yes|y)
             echo "you choose Yes";;
          [N|n]*)
             echo "you choose No";;
          esac




          posted on 2011-02-22 09:06 Aaron.Chu 閱讀(1300) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2011年2月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272812345
          6789101112

          留言簿(5)

          隨筆檔案(57)

          相冊(cè)

          友情鏈接

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 仪征市| 改则县| 江川县| 繁峙县| 平山县| 桂东县| 绵竹市| 河北省| 宝丰县| 汶川县| 承德市| 犍为县| 外汇| 皮山县| 固镇县| 襄樊市| 瑞金市| 略阳县| 应用必备| 广灵县| 彭阳县| 芒康县| 江门市| 寿宁县| 诏安县| 门源| 福贡县| 武平县| 南宫市| 庄浪县| 临朐县| 佛坪县| 丰城市| 宜兰市| 金寨县| 白银市| 星子县| 万宁市| 时尚| 双鸭山市| 丹凤县|