bash while loop breaking too early -
i'm relatively new bash (programming in general) , have been self taught part, have while loop supposed exit if conditions met.
while [[ "$var1" != "$var1_tgt" ]] && [[ "var2" != "$var2_tgt" ]] && [[ "$var3" != "$var3_tgt" ]] && [[ "$var4" != "$var4_tgt" ]]; loop...; done
the problem seem having (i think) in evaluation of loop. when run script break if 1 of conditions met, want loop break when conditions have been satisfied. is, when var# equals var#_tgt var's, should loop break. far know using "&&" should mean conditions must met before loop exit, fact it's not working means missing something. appreciate figuring out.
you need change loop to:
while [[ "$var1" != "$var1_tgt" ]] || [[ "var2" != "$var2_tgt" ]] || [[ "$var3" != "$var3_tgt" ]] || [[ "$var4" != "$var4_tgt" ]]; loop...; done
since want continue loop if any of variables not yet @ target.
otherwise, 1 of variables reaches target, 1 of conditions fail , loop break.
Comments
Post a Comment