在 zsh 中针对任意字符串测试 glob?

Test glob against an arbitrary string in zsh?

是否可以在 zsh 中测试一个字符串是否匹配一个 glob?这将完全独立于文件路径。具体来说,我想知道是否有一个命令(称之为 testglob)允许我检查一个字符串是否被认为与 glob 匹配,如下所示:

testglob '^s*' string_that_matches
testglob '^s*' does_not_match

我希望这两个命令的 return 值不同。

如果此功能尚不存在,考虑添加它是一个很好的功能。它将允许外部应用程序访问 zsh 的 globbing 系统,而无需模拟其 globbing 规则。

[[ ... ]] 命令使用常规 == 运算符执行此操作。

if [[ string == s* ]]; then
   echo string starts with s
fi