1. 程式人生 > >shell指令碼值if語句

shell指令碼值if語句

在shell指令碼中的if語句的語法和java中或者C語言中的語法格式是不一樣的,具體的語法格式如下所示:

整數變量表達式

            if [ a -eq b ] //== equal
           if [ a -ne b ] //!= not equal
           if [ a -ge b ] //>= greater equal
           if [ a -gt b ] //> greater than
           if [ a -le b ] //<= less equal
           if [ a -lt b ] //< less than
 
          if [ $age -lt 20 ]; then echo young ; elif [ $age -le 40 ]; then echo middle ; else echo old; fi

           //判斷是否是檔案
         if [ -f 1.txt ] ; then echo "1.txt是檔案" ; else echo "1.txt不是檔案" ; f

引數指定:
  ============================================

            $? //命令的返回值儲存變數
            $# //引數個數
           $1 //第1個引數
            $0 //當前指令碼(命令)名稱
           

[email protected] //取出所有引數