Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash while loop with two string conditions

I have run into a bit of a problem with my bash script. 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 [ $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. If thats the case, the thing should still be in the loop, shouldn't it? Seems my loop is exiting prematurely.

Joe

like image 890
Joe Andolina Avatar asked Jul 09 '13 00:07

Joe Andolina


1 Answers

[ .. ] doesn't match by glob. Use [[ .. ]]:

if [ "$response" == "" ] || [[ "$response" == *"404 Not Found"* ]]; then
like image 127
that other guy Avatar answered Oct 16 '22 19:10

that other guy