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


边栏推荐
- Map making of environmental impact assessment based on remote sensing interpretation and GIS technology
- Axi protocol (4): signals on the Axi channel
- 新导则下的防洪评价报告编制方法及洪水建模
- An online accident, I suddenly realized the essence of asynchrony
- List converted to tree real use of the project
- JVM Lecture 5: how to deal with peak push of vertical and horizontal data
- C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希
- Teach you how to use code to realize SSO single sign on
- C语言力扣第42题之接雨水。四种方法——暴力、动态规划、栈、双指针
- no networks found in /etc/cni/net.d
猜你喜欢

Mysql主从同步及主从同步延迟解决方案

Security permission management details

DOM事件流 事件冒泡-事件捕获-事件委托
![[acwing] 1268. Simple questions](/img/f3/7eeae566dd74d77cf6f8b4640e4f29.png)
[acwing] 1268. Simple questions

JVM第二讲:类加载机制

Leetcode linked list problem - 203. remove the linked list elements (learn the linked list by one question and one article)

分布式ID的常用解决方案-一把拿下

嵌入式分享合集20

Recommend 12 academic websites for free literature search, and suggest to like and collect!
![Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning](/img/87/9f8353c5c9c700eaa63f66697aa44a.png)
Meta analysis [whole process, uncertainty analysis] method based on R language and meta machine learning
随机推荐
Please elaborate on the implementation principle of synchronized and related locks
遥感、GIS和GPS技术在水文、气象、灾害、生态、环境及卫生等领域中的应用
MySQL八股知识点:从入门到删库
嵌入式分享合集20
I talked with the interviewer about MySQL optimization in five dimensions
Excel VBA:按日期汇总计算输出结果(sumif)
Shell的read 读取控制台输入、read的使用
Redis expiration deletion strategy and memory obsolescence strategy
注解@Autowired如何自动装配
测试用例评审如何开展
Seata两阶段提交AT详解
MODFLOW flex, GMS, FEFLOW, hydraus practical application
Go-Excelize API源码阅读(六)—— DeleteSheet(sheet string)
基于通用优化软件GAMS的数学建模和优化分析
第二讲 初识SLAM
Leetcode linked list problem - 203. remove the linked list elements (learn the linked list by one question and one article)
Security permission management details
安装NCCL\mpirun\horovod\nvidia-tensorflow(3090Ti)
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
[acwing] 1268. Simple questions