shell ,流程控制

#如果ps -ef | grep -c "ssh"的结果大于一行,打印true

if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi


#判断两个变量是否相等

a=10
b=20
if [ $a == $b ]
then
   echo "a 等于 b"
elif [ $a -gt $b ]
then
   echo "a 大于 b"
elif [ $a -lt $b ]
then
   echo "a 小于 b"
else
   echo "没有符合的条件"
fi

输出

a 小于 b

#test命令连用

num1=$[2*3]
num2=$[1+5]
if test $[num1] -eq $[num2]
then
    echo '两个数字相等!'
else
    echo '两个数字不相等!'
fi

输出

两个数字相等!


猜你喜欢

转载自www.cnblogs.com/sea-stream/p/9882237.html