jeudi 15 février 2018

How to if "x" match any of an array

I want to know how to write in bash an if statement with select command that echo a prompt error in case non correct option is given.

"The $strings variable is a column of strings."

menu() {

strings=$(echo "$(awk -F'[][]' '{ print $(2) }' file | awk NF)")

    select string in $strings
        do
            if [[ "$string" MATCH ANY "${strings[@]} ]]
                then
                    echo "you've selected $account"
                    break
                else
                    echo "Please, select one of the given options." && sleep 2
                    clear && menu
            fi
        done
}

I tried with:

if [[ "$string" =~ "${strings[@]} ]]

But does not work. Can someone help me?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire