当前位置:网站首页>Shell process control (emphasis), if judgment, case statement, let usage, for ((initial value; loop control condition; variable change)) and for variable in value 1 value 2 value 3..., while loop
Shell process control (emphasis), if judgment, case statement, let usage, for ((initial value; loop control condition; variable change)) and for variable in value 1 value 2 value 3..., while loop
2022-07-27 10:00:00 【Redamancy06】
1. Process control ( a key )
1.1if Judge
1.1.1 Basic grammar
matters needing attention :
①[ Conditional judgment ], There must be a space between the bracket and the conditional judgment
②if Space after
1.1.1.1 Single branch
if [ Conditional judgment ];then
Program
fi
perhaps
if [ Conditional judgment ]
then
Program
fi
1.1.1.2 Multiple branches
if [ Conditional judgment ]
then
Program
elif [ Conditional judgment ]
then
Program
else
Program
fi
1.1.2 Case study
1.1.2.1 Single branch



When it's written like this , When no parameters are passed in , The complains , So follow the following steps


In this way, there will be no error , Because if you don't enter parameters, neither side will be empty
1.1.2.2 With logic and && Logic or || Connect ( Single branch )
1.1.2.2.1 Logic and &&

Don't use the words in brackets && It's about using -a(-and)

1.1.2.2.2 Logic or ||

Don't use the words in brackets || It's about using -o(-or)
1.1.2.3 Multiple branches

…


1.2case sentence
1.2.1 Basic grammar
case $ Variable name in
" value 1")
If the value of the variable is equal to the value 1, Then execute the procedure 1
;;
" value 2")
If the value of the variable is equal to the value 2, Then execute the procedure 2
;;
… Omit other branches …
*)
If none of the values of the variables are above , Then execute this procedure
;;
esac
1.2.2 matters needing attention :
(1)case Line ending must be a word “in”, Each pattern match must be in right parenthesis “)” end . (2) Double a semicolon “;;” Indicates the end of the command sequence , amount to java Medium break.
(3) final “*)” Represents the default mode , amount to java Medium default.
1.2.3 Case study cast_test.sh



1.3for loop
1.3.1 Basic grammar 1
for (( Initial value ; Cycle control conditions ; Variable change ))
do
Program
done
1.3.2 Basic grammar 2
for Variable in value 1 value 2 value 3…
do
Program
done
1.3.3 Case study
1.3.3.1for (( Initial value ; Cycle control conditions ; Variable change ))



1.3.3.2“{}” stay linux shell It represents the generation sequence

{1…100} From 1 To 100, There are two points in the middle , Don't read it wrong
1.3.3.3for Variable in value 1 value 2 value 3…

1.3.3.2 stay for In circulation $* and [email protected] The difference between

When $* and [email protected] Without double quotation marks, the output result is lower :

Their output results are consistent

When double quotation marks are added . give the result as follows :
When they are double quoted “” Inclusion time ,
$* All parameters will be taken as a whole , With “$1 $2 …$n” Form input Output all parameters ;
[email protected] Separate parameters , With “$1” “$2”…“$n” Output all parameters in the form of .
1.4while loop
1.4.1 Basic grammar
while [ Conditional judgment ]
do
Program
done
1.4.2 from 1 Add to 100



1.4.3let usage
In the new shell Supported in let Of , His language is similar to high-level language 


边栏推荐
- Intermediate and advanced test questions ": what is the implementation principle of mvcc?
- Provincial Emergency Management Department: Guangzhou can strive to promote the experience of emergency safety education for children
- About getter/setter methods
- July training (day 19) - binary tree
- 并发之线程状态转换
- Food safety | are you still eating fermented rice noodles? Be careful these foods are poisonous!
- Fundamentals of Materials Engineering - key points
- Understand chisel language. 27. Chisel advanced finite state machine (I) -- basic finite state machine (Moore machine)
- July training (day 12) - linked list
- How to use tdengine sink connector?
猜你喜欢

蚂蚁集团境外站点 Seata 实践与探索

3D face reconstruction and dense alignment with position map progression network

聊聊索引失效的10种场景,太坑了

Redis 为什么这么快?Redis 的线程模型与 Redis 多线程

Gbase 8A MPP cluster capacity expansion practice

Interview JD T5, was pressed on the ground friction, who knows what I experienced?

超赞的卡尔曼滤波详解文章
![[SCM]源码管理 - perforce 分支的锁定](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[SCM]源码管理 - perforce 分支的锁定

面试京东 T5,被按在地上摩擦,鬼知道我经历了什么?

如何使用TDengine Sink Connector?
随机推荐
吃透Chisel语言.22.Chisel时序电路(二)——Chisel计数器(Counter)详解:计数器、定时器和脉宽调制
Concurrent thread state transition
会议OA项目之会议排座功能&&会议送审的实现
July training (day 21) - heap (priority queue)
At the end of the year, I'll teach you how to get high performance!
Sentinel ten thousand word tutorial | book delivery at the end of the text
活体检测综述
直播倒计时 3 天|SOFAChannel#29 基于 P2P 的文件和镜像加速系统 Dragonfly
Simple use of tflite
面试必备:虾皮服务端15连问
拜托!面试请不要再问我 Ribbon 的架构原理
Gbase 8A MPP cluster capacity expansion practice
7/26 思维+dp+后缀数组的学习
July training (day 16) - queue
MOS drive in motor controller
7/26 thinking +dp+ suffix array learning
3D face reconstruction and dense alignment with position map progression network
PCL的ICP配准示例
July training (day 10) - bit operation
Summary of engineering material knowledge points (full)