您的位置:首页 > 运维架构 > Shell

Linux学习3之shell的if大小比对使用

2016-03-15 10:20 302 查看
if的大小比对:

#!/bin/sh

a=10
b=20

if [ $a == $b ]
then
echo "a is equal to b"
elif [ $a -gt $b ]
then
echo "a is greater than b"
elif [ $a -lt $b ]
then
echo "a is less than b"
else
echo "None of the condition met"
fi


a is less than b


if的使用:

if ... fi 语句;
if ... else ... fi 语句;
if ... elif ... else ... fi 语句。


需要注意then

具体使用:

if [ $(echo $endTime | cut -d '.' -f 2) -gt $(echo $startTime | cut -d '.' -f 2) ]; then  ... fi


参考:

【1】 http://c.biancheng.net/cpp/view/7005.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息