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

时间:2020-10-27 12:38:14

标签: bash 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可以采用多个选项, 我的代码块有什么问题?

0 个答案:

没有答案