
これは私のスクリプトです。
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'"