BUGS sql
The syntax if you do not want any short option variables at all is not very intuitive (you have to set them explicitly to the empty string).bash
若是你確實不想要任何短參數(短選項),那麼語法不是很適合。(你必須用空字符串顯示的聲明)ui
例如:spa
getopt -al arg1:,arg2:,agr3: -- "$@"
因爲上述語法只聲明瞭長參數(長選項),沒有任何短參數(短選項),解析的時候會遇到第一個參數的值沒法取到的問題。code
若是不想用任何短參數(短選項),如下爲正確的寫法:ci
getopt -o "" -al connect:,sql:,parallel:,id: -- "$@"
區別在於加了一個 -o "" ,-o表示短參數(短選項),空字符表示不用任何短參數(短選項)。文檔
總結:字符串
遇到問題,應該先去文檔裏找答案。get
這個問題就是經過 man getopt 命令獲取幫助文檔找到的解決方法。string
另外 $@ 表示參數列表,必定要加引號,這樣寫 "$@",前面的 -- 不能省略。