当前位置:网站首页>Shell脚本-case in 和正则表达式
Shell脚本-case in 和正则表达式
2022-07-01 08:36:00 【小蜗牛的路】
case in 的 pattern 部分支持简单的正则表达式,具体来说,可以使用以下几种格式:
| 格式 | 说明 |
|---|---|
| * | 表示任意字符串。 |
| [abc] | 表示 a、b、c 三个字符中的任意一个。比如,[15ZH] 表示 1、5、Z、H 四个字符中的任意一个。 |
| [m-n] | 表示从 m 到 n 的任意一个字符。比如,[0-9] 表示任意一个数字,[0-9a-zA-Z] 表示字母或数字。 |
| | | 表示多重选择,类似逻辑运算中的或运算。比如,abc | xyz 表示匹配字符串 “abc” 或者 “xyz”。 |
如果不加以说明,Shell 的值都是字符串,expression 和 pattern 也是按照字符串的方式来匹配的;本节第一段代码看起来是判断数字是否相等,其实是判断字符串是否相等。
最后一个分支*)并不是什么语法规定,它只是一个正则表达式,*表示任意字符串,所以不管 expression 的值是什么,*)总能匹配成功。
代码
#!/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
输出:
运行结果1:
Input integer number: S
letter
运行结果2:
Input integer number: ,
Punctuation
边栏推荐
- MAVROS发送自定义话题消息给PX4
- Insert mathematical formula in MD document and mathematical formula in typora
- Pipeline detection of UAV Based on gazebo
- 如何做好固定资产管理?易点易动提供智能化方案
- Intelligent water conservancy solution
- 【MFC开发(16)】树形控件Tree Control
- Redis源码学习(29),压缩列表学习,ziplist.c(二)
- Do you know how data is stored? (C integer and floating point)
- Vscode customize the color of each area
- 機動目標跟踪——當前統計模型(CS模型)擴展卡爾曼濾波/無迹卡爾曼濾波 matlab實現
猜你喜欢
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code

TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
![[JS reverse] MD5 encryption parameter cracking](/img/06/0610045d287f646479d6eb5021a067.png)
[JS reverse] MD5 encryption parameter cracking

MATLAB小技巧(23)矩阵分析--模拟退火

What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR

公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度

Intelligent water supply system solution

Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling

Maneuvering target tracking -- current statistical model (CS model) extended Kalman filter / unscented Kalman filter matlab implementation

Do you know how data is stored? (C integer and floating point)
随机推荐
factory type_id::create过程解析
Shell脚本-for循环和for int循环
基于Gazebo的无人机管道检测
Foundation: 3 Opencv getting started images and videos
Programming with C language: calculate with formula: e ≈ 1+1/1+ 1/2! …+ 1/n!, Accuracy is 10-6
固定资产管理系统让企业动态掌握资产情况
R语言观察日志(part24)--初始化设置
中小企业固定资产管理办法哪种好?
MATLAB【函数和图像】
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
Glitch free clock switching technology
长安链同步节点配置与启动
Maneuvering target tracking -- current statistical model (CS model) extended Kalman filter / unscented Kalman filter matlab implementation
Advanced C language pointer (Part 2)
内存大小端
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
Tita OKR: a dashboard to master the big picture
Internet of things technology is widely used to promote intelligent water automation management
目标检测的yolov3、4、5、6总结
又到年中,固定资产管理该何去何从?