当前位置:网站首页>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 !
边栏推荐
- 618“低调”谢幕,百秋尚美如何携手品牌跨越“不确定时代”?
- Decision tree and random forest
- Blue sky drawing bed Apple quick instructions
- 块编辑器如何选择?印象笔记 Verse、Notion、FlowUs
- Pandora IOT development board learning (HAL Library) - Experiment 8 timer interrupt experiment (learning notes)
- 自动化测试的好处
- 如何在2022年更明智地应用智能合约?
- 从零实现深度学习框架——LSTM从理论到实战【实战】
- Get wechat avatar and nickname with uniapp
- The basic grammatical structure of C language
猜你喜欢

Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法

The basic grammatical structure of C language

面试官:Redis中集合数据类型的内部实现方式是什么?

Decision tree and random forest

集合

XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
PHP uses ueditor to upload pictures and add watermarks

The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)

块编辑器如何选择?印象笔记 Verse、Notion、FlowUs

面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
随机推荐
Hiengine: comparable to the local cloud native memory database engine
R language uses lubridate package to process date and time data
手机开户选择哪家券商公司比较好哪家平台更安全
决策树与随机森林
手把手教你处理 JS 逆向之图片伪装
Fuzor 2020軟件安裝包下載及安裝教程
Is the performance evaluation of suppliers in the fastener industry cumbersome? Choose the right tool to easily counter attack!
太牛了,看这篇足矣了
Technology sharing | common interface protocol analysis
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
Can Leica capture the high-end market offered by Huawei for Xiaomi 12s?
How to realize the Online timer and offline timer in the game
C# 语言的高级应用
The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
【历史上的今天】7 月 5 日:Google 之母出生;同一天诞生的两位图灵奖先驱
Fuzor 2020软件安装包下载及安装教程
UDF implementation of Dameng database
潘多拉 IOT 开发板学习(HAL 库)—— 实验8 定时器中断实验(学习笔记)
Ten years at sea: old and new relay, dark horse rising
Debezium系列之:修改源码支持drop foreign key if exists fk