Quote the Right Side of a Pattern Match in Bash [[ ]]
Inside double brackets an unquoted right-hand variable is a glob pattern and a quoted one is plain text. Quote only the part that must stay literal in Bash.
A test with a pattern held in a variable matches something you did not expect, or fails to match what you did.
s='report.txt'
pat='*.txt'
[[ $s == *.txt ]] && echo "literal pattern: match"
[[ $s == $pat ]] && echo "unquoted variable: match, it is a glob"
[[ $s == "$pat" ]] || echo "quoted variable: no match, it is the text *.txt"
[[ '*.txt' == "$pat" ]] && echo "quoted variable: matches the star itself"
[[ $s == "report"* ]] && echo "quote only the part that must stay literal"literal pattern: match
unquoted variable: match, it is a glob
quoted variable: no match, it is the text *.txt
quoted variable: matches the star itself
quote only the part that must stay literalOn the right side of == inside double brackets, unquoted text is a pattern and quoted text is a plain string. So [[ $s == $pat ]] with pat='*.txt' globs, while [[ $s == "$pat" ]] compares against the five characters of *.txt, which only another string with a literal star equals. Mixing the two, as in "report"*, keeps one part literal and lets the star match the rest. See Conditional Constructs.
The same quoting rule applies to the right side of =~, where quotes turn a regular expression into a literal string. Always quote the left side, and quote a pattern you did not write yourself when it should be data, because a stray star or question mark changes the answer.