shell 流程控制语句

目录

  if 条件语句

  for 循环语句

  while 语句

  跳出循环

if 条件语句

if 语句

if [ 2 == 2 ]
then
    echo "PASS"
fi

fi else 语句

if [ 2 == 3 ]
then
    echo "PASS"
else
    echo "FAIL"
fi

if elif else 语句

#/bin/bash

a=2
b=2
if [ $a -gt $b ];then
    echo "a > b"
elif [ $a -lt $b ];then
    echo "a < b"
else
    echo "a = b"
fi

(())作为判断语句,大于和小于可以直接使用>和<

if (( 2 > 1 ))
then
    echo "true"
fi 

for 循环

for i in `ls /home`
do
        echo $i
done

while 语句

n=3
while (($n<=5))
do
        echo $n
        let "n++"
done

 跳出循环

break 跳出整个循环

continue 跳出本次循环

posted @ 2022-03-16 09:04  zhuang6  阅读(3)  评论(0编辑  收藏  举报