#bash:

Inside double square brackets, == and != are not string equivalence tests, but glob pattern match tests, i.e. «[[ x == ? ]]» returns 0.

You can quote the right-hand-side to escape metacharacters: «[[ $X == ‘?’ ]]»