当前位置:网站首页>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,这样代码可读性很好!
边栏推荐
- 【历史上的今天】7 月 5 日:Google 之母出生;同一天诞生的两位图灵奖先驱
- PG基础篇--逻辑结构管理(用户及权限管理)
- android中常见的面试题,2022金九银十Android大厂面试题来袭
- UDF implementation of Dameng database
- Go deep into the underlying C source code and explain the core design principles of redis
- 2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]
- 2022最新大厂Android面试真题解析,Android开发必会技术
- Oracle Chinese sorting Oracle Chinese field sorting
- Debezium系列之:修改源码支持unix_timestamp() as DEFAULT value
- Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
猜你喜欢

What are the reliable domestic low code development platforms?

Mysql database indexing tutorial (super detailed)

Fuzor 2020软件安装包下载及安装教程

企业级数据安全,天翼云是这样理解的

Web3.0时代来了,看天翼云存储资源盘活系统如何赋能新基建(下)

The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly

自动化测试的好处

ELK分布式日志分析系统部署(华为云)

Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?

Why can't Bi software do correlation analysis? Take you to analyze
随机推荐
Debezium系列之:修改源码支持unix_timestamp() as DEFAULT value
Use file and directory properties and properties
5. 数据访问 - EntityFramework集成
Go deep into the underlying C source code and explain the core design principles of redis
Go语言学习教程(十五)
Ten years at sea: old and new relay, dark horse rising
中国银河证券开户安全吗 证券开户
Thoroughly understand why network i/o is blocked?
泰山OFFICE技术讲座:由行的布局高度,谈绘制高度的高度溢出、高度缩水(全网首发)
Chinese postman? Really powerful!
2022 latest intermediate and advanced Android interview questions, [principle + practice + Video + source code]
AI open2022 | overview of recommendation systems based on heterogeneous information networks: concepts, methods, applications and resources
为什么 BI 软件都搞不定关联分析?带你分析分析
【历史上的今天】7 月 5 日:Google 之母出生;同一天诞生的两位图灵奖先驱
2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]
从外卖点单浅谈伪需求
Go语言 | 03 数组、指针、切片用法
华为让出的高端市场,小米12S靠徕卡能抢到吗?
关于 Notion-Like 工具的反思和畅想
图扑软件数字孪生智慧风电系统