当前位置:网站首页>Fundamentals of shell programming (Part 8: branch statements -case in)
Fundamentals of shell programming (Part 8: branch statements -case in)
2022-07-05 19:18:00 【Just call me Wang Yuanwai】
Preface
When your if else When the sentence is particularly long , It is recommended to use case in
Example
#!/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
Grammar standards
case expression in
pattern )
commands ;;
pattern )
commands ;;
* )
commands
esac1、case And in Between expression Is an expression , Used to match each condition , If the conditions match ,) And ;; The command line between will be interpreted and executed
2、in With the first bracket ) The condition between is the condition of the first comparison
3、 Statement executed in condition , You need to end with a double semicolon ;;
4、) The previous is conditional expression ( Regular expressions )
5、* Indicates any condition , As long as there is no matching condition in front , It's defined in * The subsequent command line will execute
6、* ) The command executed in that line , Unwanted ;;
7、 Finally esac(case Write in reverse ), Express case in End of all statements !
summary
1、 A meet shell Programming standard statements
2、 When your if else …… For a very long time , Please use case in, This code is very readable !
边栏推荐
- The basic grammatical structure of C language
- 2022最新大厂Android面试真题解析,Android开发必会技术
- 14、用户、组和权限(14)
- 全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
- Password reset of MariaDB root user and ordinary user
- 数据库 逻辑处理功能
- Technology sharing | common interface protocol analysis
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- Mathematical modeling of oil pipeline layout MATLAB, mathematical model of oil pipeline layout
- 出海十年:新旧接力,黑马崛起
猜你喜欢

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

Go deep into the underlying C source code and explain the core design principles of redis

Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测

Tianyi cloud understands enterprise level data security in this way

Oracle date format conversion to_ date,to_ char,to_ Timestamp mutual conversion

如何实现游戏中的在线计时器和离线计时器
![[AI framework basic technology] automatic derivation mechanism (autograd)](/img/9c/a5713def131dc7643cc19b3839ff0c.png)
[AI framework basic technology] automatic derivation mechanism (autograd)

JAD的安装、配置及集成IDEA

Common interview questions in Android, 2022 golden nine silver ten Android factory interview questions hit

Teach you to deal with JS reverse picture camouflage hand in hand
随机推荐
Talking about fake demand from takeout order
华为让出的高端市场,小米12S靠徕卡能抢到吗?
Apprentissage du projet MMO I: préchauffage
太牛了,看这篇足矣了
MySql中的longtext字段的返回问题及解决
JS solution force deduction daily question (12) - 556 Next larger element III (2022-7-3)
Tianyi cloud understands enterprise level data security in this way
14、用户、组和权限(14)
面试官:Redis中集合数据类型的内部实现方式是什么?
After the company went bankrupt, the blackstones came
如何在2022年更明智地应用智能合约?
Applet modification style (placeholder, checkbox style)
Is it safe for Guohai Securities to open an account online?
Mathematical modeling of oil pipeline layout MATLAB, mathematical model of oil pipeline layout
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
MMO project learning 1: preheating
1亿单身男女撑起一个IPO,估值130亿
You can have both fish and bear's paw! Sky wing cloud elastic bare metal is attractive!
不愧是大佬,字节大牛耗时八个月又一力作
什么是面上项目