当前位置:网站首页>shell script flow control statement
shell script flow control statement
2022-07-30 13:22:00 【Walking DI Five Flowers】
Table of Contents
One, if---> Conditional judgment test statement
Second, for conditional loop statement
Three, while conditional loop statement
1. if---> Conditional judgment test statement
Automatically execute the corresponding commands according to the actual situation; if is divided into single-branch structure, double-branch structure and multi-branch structure.
1. if is divided into single-branch structure: if single-branch structure consists of if, then, fi (equivalent to spoken language: if...then...)
if conditional test action ------------------------>> if directory does not exist
then command number ----------------------->> then then create this directory
fi ------------------------>> fi end
Requirements: Use the shell to automatically create a directory with a fixed name

2. The double-branch structure of if consists of if, then, else, fi
Function implementation method: perform a conditional match, if the condition matches, execute the corresponding preset command, otherwise, execute the unmatched preset command.Equivalent to the colloquial "if...then...or...then",
Requirements: Use a two-branch if conditional statement to verify whether a host is online

3. The if statement of if multi-branch structure: consists of "if, then, elif, else, fi"
Conditional judgment is performed multiple times, and the corresponding preset command will be executed once the match is successful
Requirements: Enter your grades to view grades

Second, for conditional loop statement
The for loop statement allows the script to read the information of multiple files at once, and then operate on the information one by one.But there is a range when dealing with data.The for statement couldn't be better.
Syntax composition: composed of for...in, do, done
Requirement: Create multiple users by calling the contents of the specified file using a shell script.
All users who created the user are placed in a file


Verification:

Delete multiple users at the same time


Three, while conditional loop statement
Whil and for are both conditional loop statements, the difference between the two is that the conditional loop of while does not know how many times it will be executed in the end
And for has scope and target.
Syntax composition: composed of while true, do, done
Demand: Price Guessing Game


Summary:
There are many used in shell scripts, if, for, while statements
边栏推荐
- 基于反步积分滑模摩擦补偿的光电伺服转台控制
- 第十五天笔记
- 一本通循环结构的程序设计第一章题解(1)
- Add the device library after Vivado installation
- Decoding Redis' most overlooked high CPU and memory usage issues
- 大手笔!两所“双一流”大学,获75亿元重点支持!
- [PostgreSQL] - explain SQL analysis introduction
- 【河北工业大学】考研初试复试资料分享
- Dry Goods Sharing: Various Implementation Methods of Bean Management Factory with Great Use of Small Skills
- 云主机上的MongoDB被威胁,开启AUTH认证
猜你喜欢
随机推荐
机器学习——特征选择
剑指 Offer 05. 替换空格
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
Markdown 1 - 图文音视频等
dolphinscheduler adds hana support
datax enables hana support and dolphinscheduler enables datax tasks
dolphinscheduler单机化改造
如何把Excel表格显示到邮件正文里?
R语言ggplot2可视化时间序列数据(默认时间中断部分前后自动连接起来)、创建时间分组、使用分面图(faceting)可视化时间序列数据
第十三天笔记
群晖系统安装相关文件分享
并行化快速排序设想
手慢无!阿里亿级流量高并发系统设计核心原理全彩笔记现实开源
EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?
SyntaxError: EOL while scanning string literal
【河北工业大学】考研初试复试资料分享
Add the device library after Vivado installation
C语言学习练习题:汉诺塔(函数与递归)
基于空洞补全的动态SLAM方法
漫谈金丝雀部署(Canary Deployment)









