控制流結構

控制流結構

一.   退出狀態

1.       $ echo $? 最後命令退出狀態

2.       $$ || 控制次序命令

3.       exit n 退出當前進程

4.        

二.if 語句

    if condition   

if condition
                 then
command1 if condition is true or if exit status
of condition is 0 (zero)
...
...
fi

 

if...else...fi

If given condition is true then command1 is executed otherwise command2 is executed.
Syntax:

   	        if condition
       	    then
                       condition is zero (true - 0)
                       execute all commands up to else statement

	           else
                       if condition is not true then
                       execute all commands up to fi
         	  fi
 

if-then-else

Syntax:
           if condition
           then
                       condition is zero (true - 0)
                       execute all commands up to elif statement
           elif condition1 
then condition1 is zero (true - 0) execute all commands up to elif statement elif condition2 then condition2 is zero (true - 0) execute all commands up to elif statement else None of the above condtion,condtion1,condtion2 are true (i.e. all of the above nonzero or false) execute all commands up to fi fi

 

  

         if 條件

         then 命令

fi

         三.

         1.變量值測試

         2Gerp輸出檢查

         3.用變量檢查grep輸出

         4.文件拷貝輸出檢查

         5.當前目錄測試

         6.文件權限測試:用if語句測試文件權限

         7.測試傳遞到腳本中的參數

                   $# 表示調用參數的個數

         四.Case語句

         Case in

         模式1}

                            命令1

                           

                            ;;

         模式2}

                            命令2

                           

;;

         Esac

         五.for

                  1.對for循環使用參數

                            for循環中省去in列表,它將接受命令行位置參數作爲參數

                            for params in “$@”  for params in “$*”

                   2.      for循環嵌套使用

                            for 變量名1 in 列表1

                            do

                                     for 變量名2 in 列表2

                                     do 命令1

                                     done

                            done

         六.Until

                   Until 循環執行一系列命令直到條件爲真時停止

                   格式

                   Until 條件

                   命令1

                   done

         七.While 循環

                   while 命令

                   do

                   命令1

                   命令2

                   done

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章