当前位置:网站首页>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
边栏推荐
- R语言筛选时间序列数据的子集(subset time series data)、使用window函数筛选连续日期时间范围内的数据(start参数和end参数分别指定起始和结束时间)
- Why is Prometheus a monitoring artifact sufficient to replace Zabbix?
- Decoding Redis' most overlooked high CPU and memory usage issues
- 域名抢注“卷”到了表情包?ENS逆势上涨的新推力
- 企业如何成功完成云迁移?
- 漫谈金丝雀部署(Canary Deployment)
- 【高等数学】【7】二重积分
- [Go]四、模块和包、流程控制、结构体
- 湖仓一体电商项目(二):项目使用技术及版本和基础环境准备
- 基于反步积分滑模摩擦补偿的光电伺服转台控制
猜你喜欢
随机推荐
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、width参数自定义箱图中箱体的宽度
Scala基础:数组(Array)、映射(Map)、元组(Tuple)、集合(List)
湖仓一体电商项目(二):项目使用技术及版本和基础环境准备
Greenplum 6.0有哪些不可错过的硬核升级与应用?
自从外包干了四年,基本废了...
R语言ggplot2可视化时间序列数据(默认时间中断部分前后自动连接起来)、创建时间分组、使用分面图(faceting)可视化时间序列数据
浅析TSINGSEE智能视频分析网关的AI识别技术及应用场景
Apache Log4j2漏洞
机器学习——特征选择
20220729 证券、金融
干货分享:小技巧大用处之Bean管理类工厂多种实现方式
【23考研】408代码题参考模板——链表
【软考软件评测师】自动化测试章节下篇
[BJDCTF2020]Cookie is so stable-1|SSTI injection
深度操作系统DeepinOS安装步骤和MySQL安装测试
Why is Prometheus a monitoring artifact sufficient to replace Zabbix?
第42讲:Scala中泛型类、泛型函数、泛型在Spark中的广泛应用
正确处理页面控制器woopagecontroller.php,当提交表单时是否跳转正确的页面
dolphinscheduler添加hana支持
EasyNVS云管理平台功能重构:支持新增用户、修改信息等