W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
if...elif...fi 語句是提前一個級別的控制語句,形式出幾個條件,允許 Shell 作出正確的決定。
if [ expression 1 ]
then
Statement(s) to be executed if expression 1 is true
elif [ expression 2 ]
then
Statement(s) to be executed if expression 2 is true
elif [ expression 3 ]
then
Statement(s) to be executed if expression 3 is true
else
Statement(s) to be executed if no expression is true
fi
這段代碼沒有什么特別的。這僅僅是一個系列,if 語句每一個語句else子句的一部分。下面語句是執(zhí)行的基礎上的真實情況,如果條件不為 ture,則執(zhí)行else塊。
#!/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
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: