下面这两个的输出不一样,为什么?双引号的作用是什么?
if [ -n "$str" ]; then
echo "yes"
else
echo "no"
fi
if [ -n $str ]; then
echo "yes"
else
echo "no"
fi
看这个回答吧, 解释的很清楚 http://unix.stackexchange.com/a/65633/150272
总之和shell是怎么处理语句有关, 总结一点就是
Best is to always quote variables unless you've got a very good reason not to.
能用"$变量名"的时候就用, 除非你知道为啥不用
这样就不怕被坑了...