shell的执行流控制

1.for

在这里插入图片描述练习

#!/bin/bash
for AA in {1..10}
do
    ping -c1 172.25.254.$AA  &>/dev/null && {
    echo 172.25.254.$AA
}
done

在这里插入图片描述在这里插入图片描述

2.while

在这里插入图片描述

3.until

在这里插入图片描述

4.if

在这里插入图片描述
在这里插入图片描述

#!/bin/bash
CHECK()
{
        read -p "Please input filename:" FILENAME

if [ "$FILENAME" = "exit" ]
        then
                exit
elif [ ! -e "$FILENAME" ]
        then
                echo "$FILENAME is not exist."

elif [ -L "$FILENAME" ]
        then
                echo "$FILENAME is link."

elif [ -f "$FILENAME" ]
        then
                echo "$FILENAME is common file."

elif [ -d "$FILENAME" ]
        then
                echo "$FILENAME is directory."
elif [ -S "$FILENAME" ]
        then
                echo "$FILENAME is socket."

elif [ -b "$FILENAME" ]
        then
                echo "$FILENAME is block."

elif [ -c "$FILENAME" ]
        then
                echo "$FILENAME is char."
        fi
        CHECK
}
CHECK

5.case

在这里插入图片描述
在这里插入图片描述

#!/bin/bash
case $1 in
        disk)
        watch -n 1 df -h
        ;;
        memory)
        watch -n 1 free -m
        ;;
        upload)
        watch -n 1 uptime
        ;;
esac

在这里插入图片描述

6.expect

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

7.break,continue,exit

continue 终止此次循环提前进入下个循环
break 终止当前所在语句所有动作进行语句外的其他动作
exit 脚本退出

continue

#!/bin/bash
for I in {1..10}
do
        if [ "$I" = "4" ]
        then
                echo lucky number
                continue
        fi
        echo $I
done
echo end

在这里插入图片描述在这里插入图片描述
break
在这里插入图片描述在这里插入图片描述

exit

在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值