当前位置:网站首页>Shell script case in and regular expressions
Shell script case in and regular expressions
2022-07-01 08:48:00 【Little snail's way】
case in Of pattern Some support simple regular expressions , say concretely , You can use the following formats :
| Format | explain |
|---|---|
| * | Represents any string . |
| [abc] | Express a、b、c Any one of the three characters . such as ,[15ZH] Express 1、5、Z、H Any of the four characters . |
| [m-n] | From m To n Any character of . such as ,[0-9] Represents any number ,[0-9a-zA-Z] Represents letters or numbers . |
| | | Indicates multiple selection , Similar to or operation in logical operation . such as ,abc | xyz Represents a matching string “abc” perhaps “xyz”. |
If not explained ,Shell All values are strings ,expression and pattern It is also matched in the form of string ; The first code in this section seems to determine whether the numbers are equal , In fact, it is to judge whether the strings are equal .
The last branch *) It's not a grammatical rule , It's just a regular expression ,* Represents any string , So no matter expression What is the value of ,*) Always match successfully .
Code
#!/bin/bash
printf "Input a character: "
read -n 1 char
case $char in
[a-zA-Z])
printf "\nletter\n"
;;
[0-9])
printf "\nDigit\n"
;;
[0-9])
printf "\nDigit\n"
;;
[,.?!])
printf "\nPunctuation\n"
;;
*)
printf "\nerror\n"
esac
Output :
Running results 1:
Input integer number: S
letter
Running results 2:
Input integer number: ,
Punctuation
边栏推荐
- Shell script - string
- Principle and application of single chip microcomputer - principle of parallel IO port
- C language student information management system
- 通过 代码实例 理解 浅复制 与 深复制
- 足球篮球体育比赛比分直播平台源码/app开发建设项目
- Model and view of QT
- Glitch free clock switching technology
- 1. Connection between Jetson and camera
- Qt的模型与视图
- Graduation season, I want to tell you
猜你喜欢

Ape anthropology topic 20 (the topic will be updated from time to time)

15Mo3 German standard steel plate 15Mo3 chemical composition 15Mo3 mechanical property analysis of Wuyang Steel Works

【MFC开发(16)】树形控件Tree Control

Introduction to R language

Glitch Free时钟切换技术

《单片机原理及应用》-片外拓展

Dynamic proxy

电视机尺寸与观看距离

Model and view of QT

【C】 Summary of wrong questions in winter vacation
随机推荐
What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength
Software Engineer Interview Question brushing website and experience method
Installing Oracle EE
如何高效拉齐团队认知
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
截图小妙招
FreeRTOS learning easy notes
Guidelines and principles of did
Bimianhongfu queren()
Dynamic proxy
Interrupt sharing variables with other functions and protection of critical resources
LogBack
Nacos - Configuration Management
Shell script - special variables: shell $, $*, [email protected], $$$
Matlab [functions and images]
Yolov3, 4, 5 and 6 Summary of target detection
Shell脚本-if else语句
R语言入门
日常办公耗材管理解决方案
Shell script - definition, assignment and deletion of variables