当前位置:网站首页>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 !
边栏推荐
- 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)
- The road of enterprise digital transformation starts from here
- After the company went bankrupt, the blackstones came
- PHP利用ueditor实现上传图片添加水印
- Go语言 | 03 数组、指针、切片用法
- Technology sharing | common interface protocol analysis
- Cf:b. almost Terry matrix [symmetry + finding rules + structure + I am structural garbage]
- Teach you to deal with JS reverse picture camouflage hand in hand
- You can have both fish and bear's paw! Sky wing cloud elastic bare metal is attractive!
- Windows Oracle open remote connection Windows Server Oracle open remote connection
猜你喜欢
How MySQL queries and modifies JSON data
Oracle Chinese sorting Oracle Chinese field sorting
How to realize the Online timer and offline timer in the game
Android interview, Android audio and video development
Redhat7.4 configure Yum software warehouse (rhel7.4)
Why can't Bi software do correlation analysis? Take you to analyze
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
Talking about fake demand from takeout order
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]
随机推荐
flume系列之:拦截器过滤数据
Mariadb root用户及普通用户的密码 重置
Redhat7.4 configure Yum software warehouse (rhel7.4)
How MySQL queries and modifies JSON data
Benefits of automated testing
基于FPGA的超声波测距
Go deep into the underlying C source code and explain the core design principles of redis
机器学习基础(三)——KNN/朴素贝叶斯/交叉验证/网格搜索
决策树与随机森林
Mysql如何对json数据进行查询及修改
Summer Challenge database Xueba notes, quick review of exams / interviews~
从零实现深度学习框架——LSTM从理论到实战【实战】
golang通过指针for...range实现切片中元素的值的更改
1亿单身男女撑起一个IPO,估值130亿
Debezium系列之:修改源码支持drop foreign key if exists fk
Tupu software digital twin | visual management system based on BIM Technology
Decision tree and random forest
Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
Go语言 | 02 for循环及常用函数的使用
[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day