bash string compare to multiple correct values

前端 未结 5 973
时光取名叫无心
时光取名叫无心 2020-12-01 02:41

i have the following piece of bashscript:

function get_cms {
    echo \"input cms name\"
    read cms
    cms=${cms,,}
    if [ \"$cms\" != \"wordpress\" &am         


        
5条回答
  •  星月不相逢
    2020-12-01 03:18

    Maybe you should better use a case for such lists:

    case "$cms" in
      wordpress|meganto|typo3)
        do_your_else_case
        ;;
      *)
        do_your_then_case
        ;;
    esac
    

    I think for long such lists this is better readable.

    If you still prefer the if you can do it with single brackets in two ways:

    if [ "$cms" != wordpress -a "$cms" != meganto -a "$cms" != typo3 ]; then
    

    or

    if [ "$cms" != wordpress ] && [ "$cms" != meganto ] && [ "$cms" != typo3 ]; then
    

提交回复
热议问题