传统if 从句子——以条件表达式作为if条件
传统if 从句子——以条件表达式作为 if条件
if [ 条件表达式 ]
then
command
command
command
else
command
command
fi
条件表达式
- 文件表达式
if [ -f file ] 如果文件存在
if [ -d ... ] 如果目录存在
if [ -s file ] 如果文件存在且非空
if [ -r file ] 如果文件存在且可读
if [ -w file ] 如果文件存在且可写
if [ -x file ] 如果文件存在且可执行
- 整数变量表达式
if [ int1 -eq int2 ] 如果int1等于int2 equal
if [ int1 -ne int2 ] 如果不等于 not equal
if [ int1 -ge int2 ] 如果>= greater equal
if [ int1 -gt int2 ] 如果> greater than
if [ int1 -le int2 ] 如果<= less equal
if [ int1 -lt int2 ] 如果< less than
- 字符串变量表达式
If [ $a = $b ] 如果string1等于string2 字符串允许使用赋值号做等号
if [ $string1 != $string2 ] 如果string1不等于string2
if [ -n $string ] 如果string 非空(非0),返回0(true)
if [ -z $string ] 如果string 为空
if [ $sting ] 如果string 非空,返回0 (和-n类似)
最新文章
- 【processing】小代码
- java web开发必备知识
- 如何在VS C++中高亮用户自定义关键字
- Ubuntu虚拟机与Window、Arm的通信
- SpringMVC Maven创建项目
- poj Pie
- Intel 编译Boost库
- DevExtreme 学习应用[3]
- jsp页面的地址
- 微信小程序域名配置问题
- IntelliJ IDEA编辑器光标定位错误的问题!
- markdown 相关零碎知识
- Linux 定时任务 crontab 和 Systemd Timer
- Python3学习之路~0 目录
- JavaScript对象继续总结
- 用C#自定义一个简单的集合
- Java应用中使用ShutdownHook友好地清理现场
- 论 BUG调试与(程序猿)初学者
- 【LeetCode】Permutations II 解题报告
- mysql select *... where id in (select 字符串 from ... )查询结果问题?