<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # **一、if語法結構** ## **1. 單分支結構** ``` if < 條件表達式 > then 指令 fi ``` 或者 ``` if < 條件表達式 >;then 指令 fi ``` ## **2. 雙分支結構** ``` if < 條件表達式 > then 指令1 else 指令2 fi ``` ## **3. 多分支結構** ``` if < 條件表達式1 > then 指令1 elif < 條件表達式2 > then 指令2 elif < 條件表達式3 > then 指令3 else 指令4 fi ``` >條件表達式可以是test、[]、[[]]、(())等,也可以直接使用命令作為條件表達式 每個if語句都以if開頭,并帶有then,最后以fi結尾 多分支每個elif后也要帶then,但else后不帶then ## **4. 條件表達式和if語句的變換** 符號條件表達式能夠轉換為if語句,如下 ``` [ -f /etc/passwd ] && echo 1 || echo 0 ``` 等同于 ``` if [ -f /etc/passwd ] then echo 1 else echo 0 fi ``` > 其他條件表達式類似 # **二、case語句說明和語法** ## **1. 說明** * case語句相當于多分枝的if/elif/else條件語句,但看起來更工整,常用于實現系統服務啟動腳本等應用中 * case主要是寫服務的啟動腳本,適用范圍較窄 * if取值判斷、比較,應用面比case更廣,幾乎所有case語句都可以用if實現 ## **2. 語法** ``` case "變量" in 值1) 指令1... ;; 值2) 指令2... ;; *) 指令3... esac ``` 說明: * 如果變量的值等于值1時,則執行該值后面的指令1直到遇到`;;`后停止,然后跳出case語句,執行case語句后面的其他指令 * 如果沒有匹配到任何值,則執行`*)`后面的指令,該指令通常是提示用戶的指令,最后一個值可以省略雙分號 * 表達式值支持管道、正則等多功能匹配 ## **3. 簡單實踐** 根據用戶輸入判斷用戶輸入的哪個數值,并輸出,如果非數值,則提示錯誤 * `cat /server/scripts/b7.sh` ```shell #!/bin/bash read -p "pls input num[1-9]" num case "$num" in 1) echo "the num is 1" ;; 2) echo "the num is 2" ;; [3-9]) echo "the num is $num" ;; *) echo "pls input num,3q" esac ``` **執行腳本查看結果:** > * `sh /server/scripts/b7.sh ` pls input num[1-9]1 the num is 1 > * `sh /server/scripts/b7.sh` pls input num[1-9]3 the num is 3 > * `sh /server/scripts/b7.sh` pls input num[1-9]g pls input num,3q
                  <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>

                              哎呀哎呀视频在线观看