I wrote a script that contains an until
loop. This loop should run till a boolean variable is set to true
from outside the loop. Unfortunately the loop ignores that the variable has been set to true and keeps running. Here are a few lines which generate this problem:
boolean=false
{ sleep 5 && boolean=true && echo "boolean is true now" ; } &
{ until [ "$boolean" = true ] ; do sleep 1 && echo $boolean ; done ; } &&
echo "boolean is true now: $boolean"
The output this generates is:
false
false
false
false
boolean is true now
false
false
false
...
How can I make the loop exit when the boolean
is set to true
?