一个重要的原因是字符串中间有空格。
解决方法,变量放到双引号内。
a1="hello, shell"
a2="hello, shell"
if [ "$a1" == "$a2" ]
then
echo "eq"
else
echo "NotEQ"
fi
写成一行
$ if [ "$a1" == "$a2" ]; then echo "eq"; else echo "NotEQ"; fi
输出都是 eq
一个重要的原因是字符串中间有空格。
解决方法,变量放到双引号内。
a1="hello, shell"
a2="hello, shell"
if [ "$a1" == "$a2" ]
then
echo "eq"
else
echo "NotEQ"
fi
写成一行
$ if [ "$a1" == "$a2" ]; then echo "eq"; else echo "NotEQ"; fi
输出都是 eq