shell 字符串比较是否相等 报错[: =: unary operator expected
egg:
a = '123'
b='1234'
if [ $a == $b ];then
echo "相等"
fi
此时报错[: =: unary operator expected
正确写法 多加个[ ]:
if [[ $a == $b ]];then
echo "相等"
fi
本文深入解析了Shell脚本中字符串比较的正确语法,通过实例对比了常见错误与正确写法,帮助读者理解如何避免[:=:unary operator expected错误,掌握正确的条件判断语句。
shell 字符串比较是否相等 报错[: =: unary operator expected
egg:
a = '123'
b='1234'
if [ $a == $b ];then
echo "相等"
fi
此时报错[: =: unary operator expected
正确写法 多加个[ ]:
if [[ $a == $b ]];then
echo "相等"
fi

被折叠的 条评论
为什么被折叠?