这是我的脚本
if [[ ! $url == *.txt ]]
then
exit
fi
我也尝试过:
if [[ ! "$url" == *.txt ]]
then
exit
fi
和:
if [[ "$url" !== *.txt ]]
then
exit
fi
但即使$url
包含*.txt
它仍然exit
是吗?
答案1
不等式的正确运算符是!=
。见下文:
url=/heads/paths/lol.txt
if [[ $url != *.txt ]] ; then echo "does not contain txt"; else echo "contains txt"; fi
它给:
contains txt
答案2
你应该做这个:
[ -n "${url%%*.txt}" ] &&
echo "\$url is not null and does not end with the string '.txt'"