Problem with While loop.

Hi Script Gurus,

I am facing issue with while loop in bash. The while loop is running as end less loop even after given criteria does not meet.

STATE_BEFORE_SPLIT () {
    for clone in $Clonegroups; do
        state=$( $Navicmd -listclone -name $clone -cloneid $Cloneid |awk '/^CloneState:/ {print $2}' |grep Synchronizing )
        while [ "$state" = "Synchronizing" ]; do
            for clone in $Clonegroups; do
                $Navicmd -listclone -name $clone -cloneid $Cloneid -PercentSynced|egrep 'Name|PercentSynced'|paste - - |egrep -v 'N/A|100'
            done
            sleep 120
        done
    done
}

In above code while /do loop does not end even after my test strings status changed from "Synchronizing" to some other state.

Any help is appreciated.

Add a set -x in the line above the while -test. Add a set +x below it's end. Alternatively you can add in an echo to make sure the value of $state is what is expected.

The variable $state is set before the while loop, but not in the loop, so it never changes

1 Like

Thank you so much for pointing it. Somehow I was missing this. I will try to change my script now. I appreciate your quick help.