if...else...fi 語句是控制語句,它允許下一個表格執(zhí)行語句 Shell 更可控的方式在兩個選擇之間作出決定。
if [ expression ]
then
Statement(s) to be executed if expression is true
else
Statement(s) to be executed if expression is not true
fi
Shell expression 求值。如果結果值是真實的,給定 statement(s) 被執(zhí)行。如果表達式為 false,則語句將不會被執(zhí)行。
如果我們把上面的例子中,那么它可以用更好的方式使用 if...else 語句如下:
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
這將產生以下結果:
a is not equal to b
更多建議: