当前位置:网站首页>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
esac
1、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 !
边栏推荐
- Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
- shell编程基础(第9篇:循环)
- 关于 Notion-Like 工具的反思和畅想
- android中常见的面试题,2022金九银十Android大厂面试题来袭
- Technology sharing | interface testing value and system
- Postman核心功能解析 —— 参数化和测试报告
- PG基础篇--逻辑结构管理(用户及权限管理)
- Windows Oracle open remote connection Windows Server Oracle open remote connection
- CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]
- 为什么 BI 软件都搞不定关联分析?带你分析分析
猜你喜欢
Fuzor 2020 software installation package download and installation tutorial
Tianyi cloud understands enterprise level data security in this way
Analysis of postman core functions - parameterization and test report
cf:B. Almost Ternary Matrix【對稱 + 找規律 + 構造 + 我是構造垃圾】
PHP uses ueditor to upload pictures and add watermarks
Go语言 | 03 数组、指针、切片用法
强化学习-学习笔记4 | Actor-Critic
MMO項目學習一:預熱
2022 the latest big company Android interview real problem analysis, Android development will be able to technology
Django使用mysqlclient服务连接并写入数据库的操作过程
随机推荐
golang通过指针for...range实现切片中元素的值的更改
HAC集群修改管理员用户密码
cf:B. Almost Ternary Matrix【對稱 + 找規律 + 構造 + 我是構造垃圾】
Android interview, Android audio and video development
大厂面试必备技能,2022Android不死我不倒
Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
Technology sharing | interface testing value and system
块编辑器如何选择?印象笔记 Verse、Notion、FlowUs
如何实现游戏中的在线计时器和离线计时器
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)
Debezium系列之:postgresql从偏移量加载正确的最后一次提交 LSN
2022 the latest big company Android interview real problem analysis, Android development will be able to technology
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
Technology sharing | common interface protocol analysis
Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
Pandora IOT development board learning (HAL Library) - Experiment 8 timer interrupt experiment (learning notes)
How to quickly advance automated testing? Listen to the personal feelings of the three bat test engineers
Hiengine: comparable to the local cloud native memory database engine
从零实现深度学习框架——LSTM从理论到实战【实战】
MySQL中字段类型为longtext的值导出后显示二进制串方式