Check if a variable exists in a list in Bash

后端 未结 17 506
囚心锁ツ
囚心锁ツ 2020-11-29 17:08

I am trying to write a script in bash that check the validity of a user input.
I want to match the input (say variable x) to a list of valid values.

<
17条回答
  •  春和景丽
    2020-11-29 17:51

    You can use (* wildcards) outside a case statement, too, if you use double brackets:

    string='My string';
    
    if [[ $string == *My* ]]
    then
    echo "It's there!";
    fi
    

提交回复
热议问题