Bash:- getopts如何实现选项互斥以及结合冒号用法

_OPT_=()
while getopts ":p:l:d" opt;do case "${opt}" in p) _OPT_=("1" ${_OPT_[@]}) ;; l) _OPT_=("2" ${_OPT_[@]}) ;; d)
              OPTION="" _OPT_=("3" ${_OPT)[@]}) ;; :) ;; \?) ;; esac done shift $((${OPTIND} - 1))
_OPT_=($(for in in ${_OPT_[@]};do echo ${i};done | sort -n)) char="$(echo ${_OPT_[@]} | sed 's/ //g')" case "${char}" in 12) : ;; 13) : ;; *) echo "请检查命令行是否正确" exit 1 ;; esac

: ${OPTION="-B --add-drop-table=false"}

 由上面代码所知,如果选项中没有d,即不会产生OPTION为空,最后由

: ${OPTION="-B --add-drop-table=false"}来赋值
posted @ 2017-02-17 17:42  ithandonglin  阅读(398)  评论(0)    收藏  举报