Zenity, While, and Conditions

All,

I'm having fighting a losing battle with what I though would be simple.

My goal is this: Show a zenity progress or info dialog until the system obtains an ip address, then close the dialog and continue through the rest of the script.

Right now I've got the following:

ip=`ifconfig | grep 'inet ' | grep -v -c '127.0.0.1'`

just grabbing the number of ip addresses.

if [ $ip -eq 0 ]; then
while [ $ip -eq 0 ]
do
     ip=$(ifconfig | grep 'inet ' | grep -v -c '127.0.0.1')
     zenity --info --no-wrap --text "You are not currently connected to the internet. Please check your router and connections"
else
     pkill zenity
done
fi

Now I thought I was dictating that if the number of ip addresses is 0, keep checking until it isn't; also show a zenity dialog. Then, when the number no longer equals 0, exit the loop and kill the zenity box. With the exception of zenity automatically closing, everything else works, as if I switch to echoing right in the terminal it works perfectly. I think this could be useful for a lot of different applications requiring user action, but not requiring an explicit "ok" from the user after the action has been taken.

Anyone care to educate me?

---------- Post updated 10-25-12 at 10:09 AM ---------- Previous update was 10-24-12 at 06:11 PM ----------

Bump.

Have I stumped this forum as well?

try moving lines:

else
     pkill zenity

after line:

done

rdrtx1,

Thank you, I appreciate you taking the time to respond. I've just now found a solution similar to what you recommended.

Rather than using 'if' at all I've managed to fit it all into a 'while'

while [ $ip -le 0 ]
do
        ip=$(ifconfig | grep 'inet ' | grep -v -c '127.0.0.1')
        sleep 2
        echo checking
done | zenity --progress --pulsate --auto-close

Much shorter, and not doing any nasty pkills. Hopefully someone else will find this useful as well. :slight_smile: