How to use patterns in a case statement?

后端 未结 3 1631
天涯浪人
天涯浪人 2020-12-04 09:52

The man page says that case statements use \"filename expansion pattern matching\".
I usually want to have short names for some parameters, so

3条回答
  •  抹茶落季
    2020-12-04 10:04

    I don't think you can use braces.

    According to the Bash manual about case in Conditional Constructs.

    Each pattern undergoes tilde expansion, parameter expansion, command substitution, and arithmetic expansion.

    Nothing about Brace Expansion unfortunately.

    So you'd have to do something like this:

    case $1 in
        req*)
            ...
            ;;
        met*|meet*)
            ...
            ;;
        *)
            # You should have a default one too.
    esac
    

提交回复
热议问题