当前位置:网站首页>Shell script case in statement
Shell script case in statement
2022-07-01 08:48:00 【Little snail's way】
Code
#!/bin/bash
printf "Input integer number: "
read num
case $num in
1)
echo "Monday"
;;
2)
echo "Tuesday"
;;
3)
echo "Wednesday"
;;
4)
echo "Thursday"
;;
5)
echo "Friday"
;;
6)
echo "Saturday"
;;
7)
echo "Sunday"
;;
*)
echo "error"
esac
Output :
Input integer number:3
Wednesday
grammar
case expression in
pattern1)
statement1
;;
pattern2)
statement2
;;
pattern3)
statement3
;;
……
*)
statementn
esac
case,in,esac Is the key word ,expression Expression ,pattern Represents a match pattern .
case Will expression The value of is equal to pattern1、pattern2、pattern3 Match one by one :
- If expression And a pattern ( such as pattern2) The match is successful , Will execute this mode ( such as pattern2) All the following corresponding statements ( This statement can have a , There can be more than one ), Until I met a double semicolon
;;Just stop ; And then the whole case The statement is executed , The program will jump out of the whole case sentence , performesacOther subsequent statements . - If expression No match to any pattern , Then execute
*)Subsequent statements (* Represents all other values ), Until I met a double semicolon;;perhapsesacIt's over .*)It's equivalent to more than one if The last in a branch statement else part .there ;; and *) Is equivalent to its Java Medium break and default.
Yes *) Several notes of :
- Shell case in Statement
*)be used for “ Toddy ”, In case expression No match to any pattern ,*)Part can do some “ aftermath ” Work , Or give the user some tips . - There can be no
*)part . If expression No match to any pattern , Then do nothing .
Except for the last branch ( This branch can be a normal branch , It can also be *) Branch ), Each of the other branches must be preceded by ;; ending ,;; Represents the end of a branch , If you don't write, there will be grammatical errors . The last branch can write ;;, Or not , Because anyway , Execute to esac Will end the whole case in sentence .
边栏推荐
- Advanced C language pointer (Part 2)
- Computer tips
- 目标检测的yolov3、4、5、6总结
- Shell脚本-echo命令 转义符
- 【MFC开发(17)】高级列表控件List Control
- Properties of 15MnNiNbDR low temperature vessel steel, Wugang 15MnNiDR and 15MnNiNbDR steel plates
- 1. Connection between Jetson and camera
- What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
- Matlab [function derivation]
- 公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度
猜你喜欢
随机推荐
Insert mathematical formula in MD document and mathematical formula in typora
Yolov3, 4, 5 and 6 Summary of target detection
R语言入门
【MFC开发(17)】高级列表控件List Control
3、Modbus通讯协议详解
Audio-AudioRecord create(一)
C语言指针的进阶(上篇)
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
Share 7 books I read in the first half of 2022
固定资产管理系统让企业动态掌握资产情况
Model and view of QT
Advanced level of C language pointer (Part 1)
Screenshot tips
Embedded Engineer Interview Question 3 Hardware
Serial port to WiFi module communication
【C】 Summary of wrong questions in winter vacation
Vscode customize the color of each area
动态代理
任务、线程、进程 区别
基础:2.图像的本质









