当前位置:网站首页>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 !
边栏推荐
- 块编辑器如何选择?印象笔记 Verse、Notion、FlowUs
- 决策树与随机森林
- Can Leica capture the high-end market offered by Huawei for Xiaomi 12s?
- What are the reliable domestic low code development platforms?
- [today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
- 2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]
- Why can't Bi software do correlation analysis? Take you to analyze
- MMO項目學習一:預熱
- Is it safe for China Galaxy Securities to open an account? Securities account opening
- vagrant2.2.6支持virtualbox6.1版本
猜你喜欢
Tianyi cloud understands enterprise level data security in this way
JAD installation, configuration and integration idea
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
公司破产后,黑石们来了
The problem of returning the longtext field in MySQL and its solution
2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]
IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
Android面试,android音视频开发
Common interview questions in Android, 2022 golden nine silver ten Android factory interview questions hit
华为让出的高端市场,小米12S靠徕卡能抢到吗?
随机推荐
Go语言 | 01 WSL+VSCode环境搭建避坑指南
cf:B. Almost Ternary Matrix【对称 + 找规律 + 构造 + 我是构造垃圾】
Debezium系列之:解析默认值字符集
Django使用mysqlclient服务连接并写入数据库的操作过程
测试外包公司怎么样?
C# 语言的基本语法结构
Is it safe for China Galaxy Securities to open an account? Securities account opening
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
Postman核心功能解析 —— 参数化和测试报告
Fuzor 2020软件安装包下载及安装教程
HiEngine:可媲美本地的云原生内存数据库引擎
Go语言学习教程(十六)
中国银河证券开户安全吗 证券开户
Is it safe for Guohai Securities to open an account online?
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
#夏日挑战赛# HarmonyOS - 实现消息通知功能
ELK分布式日志分析系统部署(华为云)
golang通过指针for...range实现切片中元素的值的更改
Benefits of automated testing
PHP利用ueditor实现上传图片添加水印