if语句的几种常用方法
- if then fi
if command
then
commands
fi
- if then else fi
if command
then
commands
else
commands
fi
- if then elif then fi
if command1
then
commands
elif command2
then
more commands
fi
PS:
1.if-then语句允许你使用布尔逻辑来组合测试,有两种布尔运算符可用:
[ condition ] && [ condition2 ]
[ condition ] || [ condition2 ]
2.双圆括号命令允许你将高级数学表达式放入比较中:
(( expression ))
3.双方括号里的expression使用了test命令中采用的标准字符串进行比较。但他提供了test命令未提供的另一种特性—-模式匹配
[[ expression ]]