Bash 如何在while循环中使用curl的值?
即使状态变为“向上”,而“待”也将继续。为什么我不能在循环中使用变量作为条件Bash 如何在while循环中使用curl的值?,bash,while-loop,Bash,While Loop,即使状态变为“向上”,而“待”也将继续。为什么我不能在循环中使用变量作为条件 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."b
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
export confup=false
导出blup=false
超时30 bash您没有在循环中每次执行curl
。它只执行一次,结果被替换到here文档中
您应该使用此处引用的文档,以便不在原始文档上执行变量和命令替换。然后您也不需要在$blup
和$confup
中转义$
也不需要导出这些变量
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
timeout 30 bash除了Barmbar给出的正确答案之外,我看不出你想要使用here DOC的好理由。它只是不必要地使事情复杂化,使代码更难维护。顺便说一句,由于您正在以子进程的形式运行here DOC,因此您对blup
和confup
的更改在(父)脚本中不可见。