当前位置:网站首页>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 


边栏推荐
- Snowflake vs. Databricks谁更胜一筹?2022年最新战报
- Final examination paper of engineering materials
- July training (day 07) - hash table
- 3D人脸重建:Joint 3D Face Reconstruction and Dense Alignment with position Map Regression Network
- Sentinel ten thousand word tutorial | book delivery at the end of the text
- GO基础知识—数组和切片
- 2016展望
- TFlite 的简单使用
- Review of in vivo detection
- July training (day 23) - dictionary tree
猜你喜欢

Brush the title "sword finger offer" day03

What happens if the MySQL disk is full? I really met you!

35 spark streaming backpressure mechanism, spark data skew solution and kylin's brief introduction

视觉SLAM十四讲笔记(一):第一讲+第二讲

XML overview

Looking for a job for 4 months, interviewing 15 companies and getting 3 offers

Meeting seating function of conference OA project & Implementation of meeting submission for approval

3D restoration paper: shape painting using 3D generative advantageous networks and recurrent revolutionary networks

Voice live broadcast system - Principles to be followed in developing push notifications

去 OPPO 面试,被问麻了
随机推荐
Understand chisel language. 26. Chisel advanced input signal processing (II) -- majority voter filtering, function abstraction and asynchronous reset
Write yourself a year-end summary. Happy New Year!
S交换机堆叠方案配置指南
LeetCode.814. 二叉树剪枝____DFS
语音直播系统——开发推送通知需要遵守的原则
About getter/setter methods
超赞的卡尔曼滤波详解文章
[scm] source code management - lock of perforce branch
学习Typescript(一)
吃透Chisel语言.24.Chisel时序电路(四)——Chisel内存(Memory)详解
Expose a technology boss from a poor family
After one year, the paper was finally accepted by the international summit
When I went to oppo for an interview, I got numb
July training (day 17) - breadth first search
July training (the 26th day) - and check the collection
3D人脸重建:Joint 3D Face Reconstruction and Dense Alignment with position Map Regression Network
达梦 PARTGROUPDEF是自定义的对象吗?
XML overview
July training (day 21) - heap (priority queue)
flash闪存使用和STM32CUBEMX安装教程【第三天】