#第一种:if ...then...fi
function test1()
{
local RET=0
if [ $RET -eq 0 ];then
echo "yes"
else
echo "no"
fi
}
#第二种: []
function test2()
{
local RET=0
[ $RET -eq 0 ] && echo "yes" || echo "no"
}
#第三种: [[ ]]
function test3()
{
local RET=0
[[ $RET -eq 0 ]] && echo "yes" || echo "no"
}
#第四种 :test命令
function test3()
{
local RET=0
test $RET -eq 0 && echo "yes" || echo "no"
}
不考虑对低版本bash和对sh的兼容的情况下,用[[]]是兼容性强,而且性能比较快,在做条件运算时候,可以使用该运算符。