Linux 下的 shell 编程之 if-else选择结构
来源:互联网 发布:python 项目打包部署 编辑:程序博客网 时间:2024/06/06 09:50
Linux 中 shell 中if else 的使用方式比较简单,. 相关的关键字有: if, elif , else, fi, 等.
1. if 的判断表达式是 []
2. if 的范围确定不是依靠 {} ,而是if fi
一 if-else 常用结构
1. if - else 结构
# 第一种写法: 需要写, 要注意缩进if [ 条件判断表达式 ] ; then 程序块儿else 程序块儿fi# 第二中写法: 不需要写, 要注意缩进if [ 条件判断表达式 ] then 程序块儿else 程序块儿fi
2. if - elif - else 结构:
# 第一种写法: 需要写, 要注意缩进if [ 条件判断表达式 ] ; then 程序块儿elif [ 条件表达式 ] ; then 程序块儿else 程序块儿fi# 第二中写法: 不需要写, 要注意缩进if [ 条件判断表达式 ] then 程序块儿elif [ 条件表达式 ] then 程序块儿else 程序块儿fi
二 if 常用举例
1. 判断分区占用率是否超过80%
#!/bin/bash#Desc统计跟分区使用率#Authzonggf#Date2016-07-02 10:39:13#获取分区使用率rate=$(df -h | grep "/dev/sda5" | awk '{print $5}' | cut -d "%" -f1)#如果分区使用率超过80%,提示警告信息if [ $rate -gt 80 ] then echo Warning! The boot is nearly full! It is already $rate% ! else echo The boot area is safe! It is $rate%fi
2. 测试if -elif -else
#!/bin/bash#Descfor test if-else-if#Authzonggf#Date2016-07-02 11:21:01read -p "请输入一个数字:" numif [ $num -eq 20 ] ; then echo "$num > 20"elif [ $num -eq 100 ] ; then echo "$num > 100"else echo "$num < 20"fi
1 0
- Linux 下的 shell 编程之 if-else选择结构
- linux之shell编程if-then-else结构
- if-else选择结构
- Linux-Shell脚本编程-学习-5-Shell编程-使用结构化命令-if-then-else-elif
- if-else双选择结构
- if else多重选择结构
- 顺序结构和选择结构的个人见解---if else
- C# 选择结构 if、if..else、if..elseif...else、switch
- linux shell if else 多个选择条件的判断语句 语法
- Linux 下的 shell 编程之 case 多分支选择
- linux shell编程 if else 语句,case语句
- 关于if/else 选择结构的一点认识
- linux shell ---if...else...fi
- linux shell中 if else
- if;if else;if else if 循环结构的用法
- linux shell 编程2(if else 判断文章的可读、可写可执行)
- linux shell 编程 3(if then else fi 字符串空的判断)
- Linux--Shell脚本(二)条件判断之if else
- Not enough space svn: zlib (uncompress): buffer error: Decompression of svndiff data failed
- shell脚本杂七杂八问题
- java泛型的学习
- for循环打印字典
- spring集成mina,包含心跳检测,实现服务端主动推送
- Linux 下的 shell 编程之 if-else选择结构
- 根据表结构自动生成JavaBean,史上最强最专业的表结构转JavaBean的工具(第1版)
- 单片机小学期总结
- TP3.2.3 in标签用法
- NDK的Linux的环境搭建(Eclipse篇)
- Linux 下的 shell 编程之 case 多分支选择
- 【jzoj4624】【字符串匹配】【kmp】
- Android相机,YV12ToRGB24,rgbToBitmap
- Linux 下的 shell 编程之 for 循环