AskMath
AskMath

Reputation: 425

Match between string and pattern

Given the following code:

template=*.ord
if [[ ${template} == 1.ord ]]; then
    echo YES
fi

I want to get YES , but I don't get it.
How can I fix it so that it's will match the pattern to 1.ord (and not the value of template)?

Upvotes: 0

Views: 57

Answers (1)

John Kugelman
John Kugelman

Reputation: 361565

Flip the arguments. The pattern needs to be on the right-hand side, unquoted.

if [[ 1.ord == ${template} ]]; then
    echo YES
fi

Upvotes: 3

Related Questions