有没有一种方法可以限制getopts仅在单个选项上工作?

问题描述

我正在用getopts编写bash脚本,其中包含多个case语句。我的要求是能够决定何时getopts可以采用多个选项,何时不可以。

while getopts "hla:d:t:k:w:e:f:i:m:u:L:D:" options
do
    case $options in
        h)
            if [[ "${OPTARG}" = -* ]]; then
                echo "Multiple options are not allowed"
                exit 1
            fi
            verboseHelpAndExit
            break
            ;;
        l)
            if [[ "${OPTARG}" = -* ]]; then
                echo "Multiple options are not allowed"
                exit 1
            fi
            if [ "$#" -gt 0 ] || [ "$1" != '-l' ]; then
                echo "No parameters allowed"
            else
                list_users
            fi
            break
            ;;
        w)
            warn="$OPTARG"
            check_for_integer $warn
            ;;
        e)
            expire="$OPTARG"
            check_for_integer $expire
            ;;

此处-h和-l不应采用任何其他选项,并且如果传递了其他任何选项,则应给出错误,但是-w和-e可以采用多个选项, 我的代码块有什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)