Time condition loop in shell

后端 未结 8 1556
故里飘歌
故里飘歌 2020-12-04 10:34

I have just started learning shell script recently, so I don\'t know much about it.

I am trying to find example of time based while loop but not having any luck.

8条回答
  •  抹茶落季
    2020-12-04 10:57

    For a more modern approach...

    Bash

    declare -ir MAX_SECONDS=5
    declare -ir TIMEOUT=$SECONDS+$MAX_SECONDS
    
    while (( $SECONDS < $TIMEOUT )); do
        # foo
    done
    

    Korn

    typeset -ir MAX_SECONDS=5
    typeset -ir TIMEOUT=$SECONDS+$MAX_SECONDS
    
    while (( $SECONDS < $TIMEOUT )); do
        # bar
    done
    

提交回复
热议问题