我使用SH shell,我试图比较一个字符串与变量的值,但if条件总是执行为真。为什么?
下面是一些代码:
Sourcesystem="ABC"
if [ "$Sourcesystem" -eq 'XYZ' ]; then
echo "Sourcesystem Matched"
else
echo "Sourcesystem is NOT Matched $Sourcesystem"
fi;
echo Sourcesystem Value is $Sourcesystem ;
即使这样也行不通:
Sourcesystem="ABC"
if [ 'XYZ' -eq "$Sourcesystem" ]; then
echo "Sourcesystem Matched"
else
echo "Sourcesystem is NOT Matched $Sourcesystem"
fi;
echo Sourcesystem Value is $Sourcesystem ;
其次,我们可以用NULL或空字符串来匹配它吗?