如果字符串变量包含通配符,如何检入shell脚本?

use*_*778 2 bash shell wildcard

我正在尝试检查字符串是否包含任何通配符.这是我失败的尝试:

#!/bin/bash
WILDCARDS='* . ? !  ] [' 
a="foo*bar"
for x in $REJECTED_WILDCARDS
do 
    if [[ "$a" == *"$x"* ]]
    then 
            echo "It's there!";
    fi 
done
Run Code Online (Sandbox Code Playgroud)

有什么建议?

Fri*_*ner 5

略短且没有循环:

if [ "$a" != "${a//[\[\]|.? +*]/}"  ] ; then
  echo "wildcard found"
fi
Run Code Online (Sandbox Code Playgroud)

参数替换删除所有通配符.字符串不再相等.