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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## getopt - 支持長參數 ## 語法 ``` -o,--options 如"ab:c::",表示可接受的短選項為-a -b -c, -a選項不接參數 -b選項后必須接參數 -c選項的參數為可選的 -l,--long 可接受的長選項,用逗號分開,冒號的意義同短選項 -n 選項后接選項解析錯誤時提示的腳本名字 ``` 實例: ``` // 聲明 -a -o為短連接參數, --arg,--options 為長連接參數 ARGS=`getopt -o ab:c:: --long along,blong:,clong:: -n "$0" -- "$@"` #將規范化后的命令行參數分配至位置參數($1,$2,...) eval set -- "${ARGS}" ``` ## 實例 <details> <summary>test.sh</summary> ``` #!/bin/bash ARGS=`getopt -o ab:c:: --long along,blong:,clong:: -n "$0" -- "$@"` # 檢測是否有未知參數,在-n 的提示后,執行 if [ $? != 0 ]; then echo "Terminating..." exit 1 fi #將規范化后的命令行參數分配至位置參數($1,$2,...) eval set -- "${ARGS}" while true do case "$1" in -a|--along) echo "Option a"; shift ;; -b|--blong) echo "Option b, argument $2"; shift 2 ;; -c|--clong) case "$2" in "") echo "Option c, no argument"; shift 2 ;; *) echo "Option c, argument $2"; shift 2; ;; esac ;; --) shift break ;; *) echo "Internal error!" exit 1 ;; esac done ``` </details> <br/> ### 錯誤提示 ``` > ./test.sh -f ./test.sh: invalid option -- 'f' Terminating... ``` ### 短選項不帶參數 ``` > ./test.sh -a Option a ``` 測試帶參數的選項,并不會報錯 ``` ./test.sh -a asd Option a ``` ### 短選項帶參數 測試必須帶參數的值 ``` > ./test.sh -b abc Option b, argument abc ``` 不帶參數,則報錯 ``` > ./test.sh -b ./test.sh: option requires an argument -- 'b' Terminating... ``` ### 短選項帶可選參數 帶參數 ``` > ./test.sh -c Option c, no argument ``` 不帶參數 ``` > ./test.sh -c abc Option c, no argument ``` ### 長選項帶可選參數 ``` > ./test.sh -clong abc Option c, argument long ```
                  <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>

                              哎呀哎呀视频在线观看