if 语句的判断条件,从本质上讲,判断的就是命令的退出状态。
语句 | 语句格式 | 同一行书写 | 注意点 | 用例1 | 用例2 | 结果 |
---|---|---|---|---|---|---|
if 语句 |
if condition then statement(s) fi |
if condition; then statement(s); fi 注意分号,否则会有语法问题 |
1. 2.最后必须以 |
|
|
|
if else 语句 两分支 |
if condition |
if condition; then statement1; else; statement2; fi | 1.如果 condition 成立,那么 then 后边的 statement1 语句将会被执行;否则,执行 else 后边的 statement2 语句。 |
|
|
|
if elif else 语句 多分支 |
if condition1 then statement1 elif condition2 then statement2 …… else statementn fi |
1.注意,if 和 elif 后边都得跟着 then。 |
|
运行结果1: 19 成年 运行结果2: 100 老年 |
原文:https://www.cnblogs.com/ting152/p/12554287.html