shell script common statement format

The if statement

if statements into a single branch, double-branch and multi-branch.

if the format of a single limb
if    (判断条件) 
then  (如果符合)
要执行的命令
fi    (结尾)
if the bifurcation format
if    (判断条件)
then  (如果符合)
则执行这个命令
else  (如果不符合)
则执行这个命令
fi    (结尾)
if multi-branch format
if    (判断条件1)
then  (如果符合)
则执行这个命令,如果不符合则向下寻找符合条件的
elif  (判断条件2)
then  (如果符合)
则执行这个命令,如果不符合则向下寻找符合条件的
elif  (判断条件3)
then  (如果符合)
则执行这个命令,如果不符合则向下寻找符合条件的
else  (如果都不符合)
如果不符合则执行这个命令

case statement

For multi-branch statement, it is a multi-select statement.

case (判断条件) in
  模式1)
  需要执行的命令
  ;;
  模式2)
  需要执行的命令
  ;;
  ......
  *)
  默认需要执行的命令
  ;;
esac

for loop

The for loop is a fixed cycle, that is, when the cycle has been known require several cycles.

for 判断条件 in 条件取值列表
do
   要执行的命令
done

while loop

Analyzing the test is repeated operating conditions, as long as the condition is satisfied repeatedly executes a corresponding command sequence (loop), the test is not satisfied or until the condition is false.

while 测试条件
do
需要执行的命令
done
Released three original articles · won praise 4 · views 90

Guess you like

Origin blog.csdn.net/qq_46102863/article/details/104094250