You need something in the until block that will change the state of the condition variable. They also don't usually take else blocks. Besides that, all your block is doing is returning whatever was captured from the external ping command. Worse yet, since the assignment to $ping is waiting on an external command, it'll wait until the ping stops.