If.Else.FI语句是下一种形式的控制语句,它允许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表达式按上述语法求值。如果输出值为true,则执行给定的语句。如果表达式为false,则不会执行任何语句。
#!/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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)