_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"}来赋值