Linux學習3之shell的if大小比對使用
阿新 • • 發佈:2019-02-18
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