[英]Bash while loop with two string conditions
I have run into a bit of a problem with my bash script. 我的bash脚本遇到了一些问题。 My script among other things is starting a server that takes some time to get going. 我的脚本和其他东西是启动服务器,需要一些时间才能开始。 In order to combat the long startup, I have put in a while loop that queries the server to see if its running yet. 为了对抗长时间启动,我已经放入了一个查询服务器的while循环,看看它是否正在运行。
while [ $running -eq 0 ]; do
echo "===" $response "===";
if [ "$response" == "" ] || [ "$response" == *"404 Not Found"* ]; then
sleep 1;
response=$(curl $ip:4502/libs/granite/core/content/login.html);
else
running=1;
fi
done
When exiting the loop $response equals the "404" string. 当退出循环时,$ response等于“404”字符串。 If thats the case, the thing should still be in the loop, shouldn't it? 如果是这样的话,那东西应该还在循环中,不应该吗? Seems my loop is exiting prematurely. 似乎我的循环过早退出。
Joe 乔
[ .. ]
doesn't match by glob. [ .. ]
与glob不匹配。 Use [[ .. ]]
: 使用[[ .. ]]
:
if [ "$response" == "" ] || [[ "$response" == *"404 Not Found"* ]]; then
I am not sure why my original script was failing. 我不确定为什么我的原始剧本失败了。 I assume it has to do with the fact that I was comparing against HTML. 我认为这与我与HTML进行比较的事实有关。 To get my script working I wound up using the string length instead of the content. 为了让我的脚本工作,我使用字符串长度而不是内容。 The using the following comparator has everything working swimmingly. 使用以下比较器,一切都在游泳。
if [ -z "$response" ] || [ ${#response} -lt 100 ]; then
Thanks for the help, Joe 谢谢你的帮助,乔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.