当前位置:网站首页>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
边栏推荐
- NFT监管要点和海外政策
- "Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
- yolov5训练可视化指标的含义
- Nacos - Configuration Management
- 中小企业固定资产管理办法哪种好?
- 1.jetson与摄像头的对接
- Shell script - string
- 避免按钮重复点击的小工具bimianchongfu.queren()
- 日常办公耗材管理解决方案
- Redis源码学习(29),压缩列表学习,ziplist.c(二)
猜你喜欢

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

factory type_ Id:: create process resolution

Audio audiorecord create (I)

MD文档中插入数学公式,Typora中插入数学公式

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

Screenshot tips

基础:2.图像的本质
![[MFC development (17)] advanced list control list control](/img/e8/24c52cb51defc6c96b43c2ef3232ff.png)
[MFC development (17)] advanced list control list control

嵌入式工程师面试题3-硬件

Dynamic proxy
随机推荐
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
Share 7 books I read in the first half of 2022
目标检测的yolov3、4、5、6总结
What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR
[untitled]
Embedded Engineer Interview Question 3 Hardware
Shell脚本-for循环和for int循环
Principle and application of single chip microcomputer - principle of parallel IO port
Shell script - definition, assignment and deletion of variables
Serial port to WiFi module communication
任务、线程、进程 区别
基础:2.图像的本质
R语言观察日志(part24)--初始化设置
Installing Oracle EE
Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
LogBack
MATLAB【函数求导】
DataBinding源码分析
Shell script - positional parameters (command line parameters)
Nacos - 服务发现