'ZSH expanded variables in [[ ... ]] do not perform globbing

I have extended_glob set in .zshrc.

This works as expected:

[[ "value" = [a-z]* ]] && echo "globbed"

Prints "globbed".

But this does not:

foo=[a-z]*
[[ "value" = $foo ]] && echo "globbed"

Doesn't print anything.
Why is that and what do I need to set, if anything, in .zshrc to make it function?



Solution 1:[1]

You can use

foo='[a-z]*'
[[ "value" == $~foo ]] && echo "globbed"

$~foo notation allows globbing in zsh.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wiktor Stribiżew