当前位置:网站首页>Shell编程基础(第8篇:分支语句-case in)
Shell编程基础(第8篇:分支语句-case in)
2022-07-05 18:58:00 【叫我王员外就行】
前言
当您的if else语句特别长的时候,建议使用case in
例子
#!/bin/bash
echo "please input a number"
read number
case ${number} in
1)
echo it is 1;;
2)
echo it is 2;;
*)
echo other number: ${number};;
esac
echo program is finish
语法标准
case expression in
pattern )
commands ;;
pattern )
commands ;;
* )
commands
esac1、case与in之间的expression为为表达式,用于和每个条件进行匹配,条件匹配的情况下,)与;;之间的命令行会被解释执行
2、in与第一个括号)之间的条件为第一个比较的条件
3、条件中执行的语句,需要以双分号表示结束;;
4、)之前的为条件表达式(正则表达式)
5、* 表示任意条件,只要前面没有匹配的条件,定义在*之后的命令行会执行
6、* )那一行中执行的命令,不需要;;
7、最后以esac(case反过来写),表示case in语句的全部结束!
总结
1、一个符合shell编程标准的语句
2、当你的if else ……特别长的时候,请使用case in,这样代码可读性很好!
边栏推荐
- HAC cluster modifying administrator user password
- JAD的安装、配置及集成IDEA
- 开源 SPL 消灭数以万计的数据库中间表
- Fuzor 2020軟件安裝包下載及安裝教程
- Debezium系列之:修改源码支持drop foreign key if exists fk
- 紧固件行业供应商绩效考核繁琐?选对工具才能轻松逆袭!
- Taishan Office Technology Lecture: from the layout height of the line, talk about the height overflow and height shrinkage of the drawing height (launched in the whole network)
- What are the reliable domestic low code development platforms?
- China law network joins hands to observe the cloud, and the online system is a full link observable platform
- Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
猜你喜欢

Technology sharing | interface testing value and system

5. Data access - entityframework integration
![2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]](/img/4b/90f07cd681b1e0595fc06c9429b338.jpg)
2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]

Mariadb root用户及普通用户的密码 重置
![[performance test] jmeter+grafana+influxdb deployment practice](/img/32/f07792734d040829398a90a2040146.png)
[performance test] jmeter+grafana+influxdb deployment practice
Django使用mysqlclient服务连接并写入数据库的操作过程

Analysis of postman core functions - parameterization and test report

面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
![Cf:b. almost Terry matrix [symmetry + finding rules + structure + I am structural garbage]](/img/5d/06229ff7cfa144dbcb60ae43d5c435.png)
Cf:b. almost Terry matrix [symmetry + finding rules + structure + I am structural garbage]

Word查找红色文字 Word查找颜色字体 Word查找突出格式文本
随机推荐
Low code practice of xtransfer, a cross-border payment platform: how to integrate with other medium-sized platforms is the core
Summary of six points of MySQL optimization
Oracle date format conversion to_ date,to_ char,to_ Timestamp mutual conversion
You can have both fish and bear's paw! Sky wing cloud elastic bare metal is attractive!
HiEngine:可媲美本地的云原生内存数据库引擎
决策树与随机森林
The road of enterprise digital transformation starts from here
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Redhat7.4 configure Yum software warehouse (rhel7.4)
Django使用mysqlclient服务连接并写入数据库的操作过程
Technology sharing | interface testing value and system
golang通过指针for...range实现切片中元素的值的更改
[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
flume系列之:拦截器过滤数据
Talking about fake demand from takeout order
word如何转换成pdf?word转pdf简单的方法分享!
华为让出的高端市场,小米12S靠徕卡能抢到吗?
XML基础知识概念
Debezium系列之:修改源码支持drop foreign key if exists fk
618“低调”谢幕,百秋尚美如何携手品牌跨越“不确定时代”?