shell ,流程控制

时间:2018-10-31 13:30:18   收藏:0   阅读:133

 

#如果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

输出

两个数字相等!

 



原文:https://www.cnblogs.com/sea-stream/p/9882237.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!