bash string compare to multiple correct values

前端 未结 5 978
时光取名叫无心
时光取名叫无心 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:21

    If the main intent is to check whether the supplied value is not found in a list, maybe you can use the extended regular expression matching built in BASH via the "equal tilde" operator (see also this answer):

    if ! [[ "$cms" =~ ^(wordpress|meganto|typo3)$ ]]; then get_cms ; fi
    

    Have a nice day

提交回复
热议问题