当前位置:网站首页>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
边栏推荐
- TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
- 毕业季,我想对你说
- Graduation season, I want to tell you
- Shell脚本-read命令:读取从键盘输入的数据
- 任务、线程、进程 区别
- "Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
- 3、Modbus通讯协议详解
- FreeRTOS学习简易笔记
- TV size and viewing distance
- 软件工程师面试刷题网站、经验方法
猜你喜欢

如何一站式高效管理固定资产?

3、Modbus通讯协议详解

Properties of 15MnNiNbDR low temperature vessel steel, Wugang 15MnNiDR and 15MnNiNbDR steel plates

NIO-零拷贝

Vscode customize the color of each area

AVL树的理解和实现

Nacos - 配置管理

What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength

Personal decoration notes

足球篮球体育比赛比分直播平台源码/app开发建设项目
随机推荐
中小企业固定资产管理办法哪种好?
[MFC development (17)] advanced list control list control
性能提升2-3倍!百度智能云第二代昆仑芯服务器上线
如何高效拉齐团队认知
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
MD文档中插入数学公式,Typora中插入数学公式
Vscode customize the color of each area
避免按钮重复点击的小工具bimianchongfu.queren()
【面试必刷101】链表
Shell脚本-for循环和for int循环
嵌入式工程师面试题3-硬件
R语言观察日志(part24)--初始化设置
Ape anthropology topic 20 (the topic will be updated from time to time)
Shell script -for loop and for int loop
《单片机原理及应用》—定时器、串行通信和中断系统
Differences among tasks, threads and processes
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
AVL树的理解和实现
日常办公耗材管理解决方案
【MFC开发(16)】树形控件Tree Control