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)
有什么建议?
略短且没有循环:
if [ "$a" != "${a//[\[\]|.? +*]/}" ] ; then
echo "wildcard found"
fi
Run Code Online (Sandbox Code Playgroud)
参数替换删除所有通配符.字符串不再相等.