How to interupt infinite while loop?


Results 1 to 2 of 2

Thread: How to interupt infinite while loop?

  1. #1
    Join Date
    Apr 2014
    Posts
    34

    How to interupt infinite while loop?

    Hello,

    i would like this loop to check some variable and if its greater than some number it will wait untill its lower.

    this while can be used:

    Code:
    while [ "$value" -gt "$value2" ];do
    
    $value2=$(...get_value2_command_here...)
    
    sleep 1
    
    done

    How it should look like if i want to stop this while and continue executing rest of the script if $value2 not become smaller than $value in like 5 minutes or in like 100 loops?

    Please anyone can share how it should look like?

  2. #2
    Join Date
    Apr 2014
    Posts
    34
    i found one solution based on number of cycles / loops:
    before while add:
    loopnumber=1
    and into while add:
    loopnumber=$((loopnumber+1))

    # Here commands that need to be executed #

    if [ "$loopnumber" -gt "60" ];then
    echo "It is 60 loops/checks now.. lets break the script now and not check more"
    break
    fi

    echo "now we continuing next script lines here"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •