这可能已经回答了,但我还是要问它。我有两个版本的脚本 ( comp.sh
)-
#!/bin/sh
export tDay=$(date '+%Y%m%d')
newfile="filename_$tDay"
filename="filename_20120821100002.csv"
echo $newfile $filename
if [ $filename = *$newfile* ]
then
echo "Matched"
else
echo "Not Matched!"
fi
Output:
$ ./comp.sh
filename_20120821 filename_20120821100002.csv
Not Matched!
和
#!/bin/sh
export tDay=$(date '+%Y%m%d')
newfile="filename_$tDay"
filename="filename_20120821100002.csv"
echo $newfile $filename
if [[ $filename = *$newfile* ]]
then
echo "Matched"
else
echo "Not Matched!"
fi
$ comp.sh
filename_20120821 filename_20120821100002.csv
Matched
有人可以解释一下为什么有区别吗?
另外 - 在什么情况下应该[ ]
使用与[[ ]]
反之亦然?