本文档为个人博客文档系统的备份版本、作者:小游、作者博客:点击访问
if语句
#语法格式
if condition
then
command1
command2
...
commandN
fi
#写成一行
if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi
#if else 语法格式
if condition
then
command1
command2
...
commandN
else
command
fi
#if elseif 语法格式
if condition1
then
command1
elif condition2
then
command2
else
commandN
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
#if else语句经常与test命令结合使用,如下所示:
num1=$