当前位置:网站首页>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,这样代码可读性很好!
边栏推荐
- EMQX 5.0 正式发布:单集群支持 1 亿 MQTT 连接
- 5. Data access - entityframework integration
- [today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
- 如何快速进阶自动化测试?听听这3位BAT大厂测试工程师的切身感想....
- 视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
- 手把手教你处理 JS 逆向之图片伪装
- You can have both fish and bear's paw! Sky wing cloud elastic bare metal is attractive!
- 机器学习基础(三)——KNN/朴素贝叶斯/交叉验证/网格搜索
- R language Visual scatter plot graph, add labels to some data points in the graph, and always display all labels, even if they have too much overlap. Ggrep package helps
- JS solution force deduction daily question (12) - 556 Next larger element III (2022-7-3)
猜你喜欢

Postman核心功能解析 —— 参数化和测试报告

How to quickly advance automated testing? Listen to the personal feelings of the three bat test engineers

Powerful tool for collection processing

android中常见的面试题,2022金九银十Android大厂面试题来袭

Ant group open source trusted privacy computing framework "argot": open and universal

Why can't Bi software do correlation analysis? Take you to analyze

一朵云开启智慧交通新未来

国内低代码开发平台靠谱的都有哪些?

Go语言 | 01 WSL+VSCode环境搭建避坑指南

如何快速进阶自动化测试?听听这3位BAT大厂测试工程师的切身感想....
随机推荐
Mysql如何对json数据进行查询及修改
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
华律网牵手观测云,上线系统全链路可观测平台
XML basic knowledge concept
Mathematical modeling of oil pipeline layout MATLAB, mathematical model of oil pipeline layout
#夏日挑战赛#数据库学霸笔记,考试/面试快速复习~
#夏日挑战赛# HarmonyOS - 实现消息通知功能
Teach you to deal with JS reverse picture camouflage hand in hand
华为让出的高端市场,小米12S靠徕卡能抢到吗?
Golang through pointer for Range implements the change of the value of the element in the slice
Oracle 中文排序 Oracle 中文字段排序
5年经验Android程序员面试27天,2022程序员进阶宝典
uniapp获取微信头像和昵称
Shang Silicon Valley Shang preferred project tutorial release
[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
Optimization of middle alignment of loading style of device player in easycvr electronic map
开源 SPL 消灭数以万计的数据库中间表
【AI 框架基础技术】自动求导机制 (Autograd)
Go语言学习教程(十五)
android中常见的面试题,2022金九银十Android大厂面试题来袭