0

even if status becomes "UP", while to be will be continue. why can't i use a variable in a loop as a condition?

export confup=false
export blup=false
timeout 30 bash <<EOF || false
while [[  $( curl http://0.0.0.0/ | jq -r '.status') != "UP" ]];
do
if [[ $( curl http://0.0.0.0/ | jq -r '.components."bridge.lock".status') == "UP" && \$blup == "false" ]]; then
    echo "true
    export blup=yes
fi
if [[ $( curl http://0.0.0.0/ | jq -r '.components."Configuration converted".status') == "UP" && \$confup == "false" ]]; then
    echo "true"
    export confup=yes
fi
echo $( curl "http://0.0.0.0/" | jq -r '.status')
sleep 5
done 
EOF
1
  • Aside from the correct answer by Barmbar, I don't see a good reason why you want to use a here-DOC. It just unnecessarily complicates things and makes your code more difficult to maintain. BTW, since you are running the here-DOC as a childprocess, your changes of blup and confup won't be visible in your (parent) script. Commented Sep 1, 2020 at 7:37

1 Answer 1

1

You're not executing curl each time through the loop. It's just being executed once and the result is substituted into the here-doc.

You should use a quoted here-doc so that the variables and command substitutions are not done on the original document. Then you also don't need to escape the $ in $blup and $confup.

There's also no need to export these variables.

timeout 30 bash <<'EOF' || false
while [[  $( curl http://0.0.0.0/ | jq -r '.status') != "UP" ]];
    do
    if [[ $( curl http://0.0.0.0/ | jq -r '.components."bridge.lock".status') == "UP" && $blup == "false" ]]; then
        echo "true"
        blup=yes
    fi
    if [[ $( curl http://0.0.0.0/ | jq -r '.components."Configuration converted".status') == "UP" && $confup == "false" ]]; then
        echo "true"
        confup=yes
    fi
    echo $( curl "http://0.0.0.0/" | jq -r '.status')
    sleep 5
done 
EOF
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.