当前位置:网站首页>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 , performesac
Other subsequent statements . - If expression No match to any pattern , Then execute
*)
Subsequent statements (* Represents all other values ), Until I met a double semicolon;;
perhapsesac
It'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 .
边栏推荐
猜你喜欢
《微机原理》—总线及其形成
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
安装Oracle EE
你了解数据是如何存储的吗?(C整型和浮点型两类)
Screenshot tips
Installing Oracle EE
Matlab [functions and images]
内存大小端
View drawing process analysis
随机推荐
Advanced API
Qt的模型与视图
Shell脚本-case in 和正则表达式
factory type_ Id:: create process resolution
Memory size end
挖财打新股安全吗
性能提升2-3倍!百度智能云第二代昆仑芯服务器上线
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
Foundation: 3 Opencv getting started images and videos
I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
中考体育项目满分标准(深圳、安徽、湖北)
Li Kou 1358 -- number of substrings containing all three characters (double pointer)
Share 7 books I read in the first half of 2022
电视机尺寸与观看距离
3、Modbus通讯协议详解
Audio-AudioRecord create(一)
It technology ebook collection
足球篮球体育比赛比分直播平台源码/app开发建设项目
FreeRTOS learning easy notes