bash中变量+=,if大小判断,随机休眠

#!/bin/bash

index=0
while true;do
    echo "hello"
    (( index+=1))
    echo `date "+%H:%M:%S"`
    if [ $index -ge 5 ];then
        exit
    fi
    sleep "$(( ( RANDOM % 3 )  + 2 ))s"
done

随机时间为 2-5(包含2) 秒

原文地址:https://www.cnblogs.com/lurenjiashuo/p/bash-plus-equal-if-lt-random-sleep.html