<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # if 語句 ## if else ### fi if 語句語法格式: ~~~ if condition then command1 command2 ... commandN fi ~~~ 寫成一行(適用于終端命令提示符): ~~~ if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi ~~~ 末尾的 fi 就是 if 倒過來拼寫,后面還會遇到類似的。 ### if else if else 語法格式: ~~~ if condition then command1 command2 ... commandN else command fi ~~~ ### if else-if else if else-if else 語法格式: ~~~ if condition1 then command1 elif condition2 then command2 else commandN fi ~~~ # for 循環 與其他編程語言類似,Shell支持for循環。 for循環一般格式為: ~~~ for var in item1 item2 ... itemN do command1 command2 ... commandN done ~~~ 寫成一行: ~~~ for var in item1 item2 ... itemN; do command1; command2… done; ~~~ 當變量值在列表里,for 循環即執行一次所有命令,使用變量名獲取列表中的當前取值。命令可為任何有效的 shell 命令和語句。in 列表可以包含替換、字符串和文件名。 in列表是可選的,如果不用它,for循環使用命令行的位置參數。 # while 語句 while 循環用于不斷執行一系列命令,也用于從輸入文件中讀取數據。其語法格式為: ~~~ while condition do command done ~~~ ### 無限循環 無限循環語法格式: ~~~ while : do command done ~~~ 或者 ~~~ while true do command done ~~~ 或者 ~~~ for (( ; ; )) ~~~ ## until 循環 until 循環執行一系列命令直至條件為 true 時停止。 until 循環與 while 循環在處理方式上剛好相反。 一般 while 循環優于 until 循環,但在某些時候—也只是極少數情況下,until 循環更加有用。 until 語法格式: ~~~ until condition do command done ~~~ condition 一般為條件表達式,如果返回值為 false,則繼續執行循環體內的語句,否則跳出循環。 # case ... esac 條件分支語句 **case ... esac**為多選擇語句,與其他語言中的 switch ... case 語句類似,是一種多分枝選擇結構,每個 case 分支用右圓括號開始,用兩個分號;;表示 break,即執行結束,跳出整個 case ... esac 語句,esac(就是 case 反過來)作為結束標記。 可以用 case 語句匹配一個值與一個模式,如果匹配成功,執行相匹配的命令。 **case ... esac**語法格式如下: ~~~ case 值 in 模式1) command1 command2 ... commandN ;; 模式2) command1 command2 ... commandN ;; esac ~~~ case 工作方式如上所示,取值后面必須為單詞**in**,每一模式必須以右括號結束。取值可以為變量或常數,匹配發現取值符合某一模式后,其間所有命令開始執行直至;;。 取值將檢測匹配的每一個模式。一旦模式匹配,則執行完匹配模式相應命令后不再繼續其他模式。如果無一匹配模式,使用星號 \* 捕獲該值,再執行后面的命令。 ## 跳出循環 在循環過程中,有時候需要在未達到循環結束條件時強制跳出循環,Shell使用兩個命令來實現該功能:break和continue。 ### break命令 break命令允許跳出所有循環(終止執行后面的所有循環)。 下面的例子中,腳本進入死循環直至用戶輸入數字大于5。要跳出這個循環,返回到shell提示符下,需要使用break命令。 ## 實例 #!/bin/bash while: do ? ?echo\-n"輸入 1 到 5 之間的數字:" ? ?readaNum ? ?case$aNumin ? ? ? ?1|2|3|4|5)echo"你輸入的數字為$aNum!" ? ? ? ?;; ? ? ? ?\*)echo"你輸入的數字不是 1 到 5 之間的! 游戲結束" ? ? ? ? ? ?break ? ? ? ?;; ? ?esac done 執行以上代碼,輸出結果為: ~~~ 輸入 1 到 5 之間的數字:3 你輸入的數字為 3! 輸入 1 到 5 之間的數字:7 你輸入的數字不是 1 到 5 之間的! 游戲結束 ~~~ ### continue continue命令與break命令類似,只有一點差別,它不會跳出所有循環,僅僅跳出當前循環。 對上面的例子進行修改: ## 實例 #!/bin/bash while: do ? ?echo\-n"輸入 1 到 5 之間的數字: " ? ?readaNum ? ?case$aNumin ? ? ? ?1|2|3|4|5)echo"你輸入的數字為$aNum!" ? ? ? ?;; ? ? ? ?\*)echo"你輸入的數字不是 1 到 5 之間的!" ? ? ? ? ? ?continue ? ? ? ? ? ?echo"游戲結束" ? ? ? ?;; ? ?esac done 運行代碼發現,當輸入大于5的數字時,該例中的循環不會結束,語句**echo "游戲結束"**永遠不會被執行。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看