当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
LogBack
Advanced API
《微机原理》——微处理器内部及外部结构
Principle and application of single chip microcomputer - principle of parallel IO port
Ape anthropology topic 20 (the topic will be updated from time to time)
C语言指针的进阶(上篇)
19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
目标检测的yolov3、4、5、6总结
通过 代码实例 理解 浅复制 与 深复制
MD文档中插入数学公式,Typora中插入数学公式
日常办公耗材管理解决方案
C language student information management system
Glitch free clock switching technology
Foundation: 3 Opencv getting started images and videos
It is designed with high bandwidth, which is almost processed into an open circuit?
R语言观察日志(part24)--初始化设置
MySQL8.0学习记录17 -Create Table
DataBinding源码分析
Advanced C language pointer (Part 2)
电视机尺寸与观看距离




![Matlab [functions and images]](/img/8a/d2f68b5a7ed396ad20234c0aa24953.jpg)



