当前位置:网站首页>(7) Process control
(7) Process control
2022-07-27 11:22:00 【Hungry Taibai Xingjun】
#!/bin/bash
# shell The process control of cannot be empty
:<<EOF
<?php
if (isset($_GET["q"])) {
search(q);
}
else {
// Not doing anything
}
stay sh/bash You can't write that in , If else Branch has no statement execution , Don't write this else.
EOF
# 1. if else
# 1.1 if grammar
:<<EOF
if condition
then
command1
command2
...
commandN
fi
Write in a line ( For terminal command prompt )
if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi
EOF
# 1.2 if else grammar
:<<EOF
if condition
then
command1
command2
...
commandN
else
command
fi
EOF
# 1.3 if else-if else grammar
:<<EOF
if condition1
then
command1
elif condition2
then
command2
else
commandN
fi
EOF
# 1.4 example
a=10
b=20
if test ${
a} -eq ${
b} # if [ $a= $b]
then
echo "a and b equal "
elif test ${
a} -gt ${
b} # elif [ $a -gt $b ]
then
echo "a Greater than b"
elif test ${
a} -lt ${
b} # [ $a -lt $b ]
then
echo "a Less than b"
else
echo " Not qualified "
fi
# 2. for loop
# grammar
:<<EOF
for var in item1 item2 ... itemN
do
command1
command2
...
commandN
done
# Write in a line
for var in item1 item2 ... itemN; do command1; command2… done;
EOF
for loop in 1 2 3 40
do
echo "The value is: ${loop}"
done
for str in This is a string.
do
echo ${
str}
done
# 3. while sentence
# 3.1 grammar
:<<EOF
while condition
do
command
done
EOF
# example
num1=1
while (( $num1<=5))
do
echo "${num1}"
let "num1++"
done
# The above example uses Bash let command , It is used to execute one or more expressions ,
# There is no need to add $ To represent a variable
# 3.2 Read keyboard information
echo -n ' Enter your favorite website name : ' # When -n Options , Then cancel the trailing newline
while read FILM
do
echo " Yes !$FILM It's a good website "
break
done
# 3.3 Infinite loop
:<<EOF
# The first one is
while :
do
command
done
# The second kind
while true
do
command
done
# The third kind of
for (( ; ; ))
EOF
# 4. until loop
# until Loop through a series of commands until the condition is true Stop when .
# until Circulation and while The cycle is the opposite of the way it's handled .
# 4.1 Grammar format
:<<EOF
until condition
do
command1
done
EOF
# example
a=0
until [ ! $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
# 5. case ... esac
# case ... esac Select multiple statements for , And in other languages switch ... case Statements like ,
# It's a multi branched selection structure , Every case The branch begins with a right parenthesis , Use two semicolons ;; Express break, The end of execution ,
# Jump out of the whole case ... esac sentence ,esac( Namely case In turn, ) As the closing tag .
#
# It can be used case Statement matches a value with a pattern , If the match is successful , Execute the matching command .
# 5.1 grammar
:<<EOF
case value in
Pattern 1)
command1
command2
...
commandN
;;
Pattern 2)
command1
command2
...
commandN
;;
esac
EOF
# Value must be followed by word in, The first mock exam must be closed with right brackets. .
# Value can be variable or constant , Match found that after the first mock exam meets a certain pattern, , During this period, all commands are executed until ;;.
# Value will detect every matching pattern . Once the patterns match , After the corresponding command of matching mode is executed, other modes will not be continued .
# If there is no matching pattern , Use the asterisk * Capture the value , Then execute the following command .
# example 1—— The number
echo " Input 1-4 Integer between "
echo " The value you entered is :"
read num11
case $num11 in
1) echo " You entered 1"
;;
2) echo " You entered 2"
;;
3) echo " You entered 3"
;;
4) echo " You entered 4"
;;
*) echo " You entered other numbers "
;;
esac
# example 2—— character string
site="runoob"
case "${site}" in
"runoob") echo " Novice tutorial "
;;
"google") echo "Google Search for "
;;
"taobao") echo " TaoBao "
;;
esac
# 6 Out of the loop
# 6.1 break: Out of the loop
# 6.2 continue: Jump out of current loop
边栏推荐
- 背包模型 AcWing 1022. 宠物小精灵之收服
- Miscellaneous records of Finance
- NFT leaderboard -nft real offer latest address: NFT leaderboard.com
- Kangaroo cloud stack based on CBO in spark SQL optimization
- Sorry, you guys have something to deal with in the bank recently, which has been delayed
- 2022 Niuke multi school (3) j.journey
- 高斯消元 AcWing 884. 高斯消元解异或线性方程组
- ethereum rpc
- 10 complete half of the questions
- Luogu p1441 weight weighing
猜你喜欢

最长上升子序列模型 AcWing 1016. 最大上升子序列和

Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?

Internal and external troubles of digital collection NFT "boring ape" bayc

中国剩余定理 AcWing 204. 表达整数的奇怪方式

容斥原理 AcWing 890. 能被整除的数

Wilderness search --- search iterations

Digital triangle model acwing 275. pass note
![[shader realizes shake random shaking effect _shader effect Chapter 10]](/img/49/99669ebc3ba59a0277bb8bc928f576.png)
[shader realizes shake random shaking effect _shader effect Chapter 10]

Instructions for mock platform

Knapsack problem acwing 9. grouping knapsack problem
随机推荐
7 row K with the weakest combat effectiveness in the matrix
Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?
49 letter ectopic grouping and 242 effective letter ectopic words
Knapsack model acwing 1024. Packing problem
最长上升子序列模型 AcWing 1014. 登山
Students, don't copy all my code, remember to change it, or we both want G
背包问题 AcWing 9. 分组背包问题
Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
Find the combination number acwing 885. find the combination number I
树形DP AcWing 285. 没有上司的舞会
I've compromised. Since everyone wants to call me Yelin, there's nothing I can do
Game theory acwing 892. Step Nim game
Properties file
Internal and external troubles of digital collection NFT "boring ape" bayc
Lazy loading of lists and pictures
Win10 vscode code code format setting and remote breakpoint debugging
Today's code farmer girl learned notes about event operation and ref attribute, and did the practice of form two-way binding
数字三角形模型 AcWing 1018. 最低通行费
349 sum of intersection of two arrays and 01