2 # wait until a host is pingable, then exit
\r
4 ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded
\r
5 until ping -c1 "$1" >/dev/null 2>&1; do :; done & # The "&" backgrounds it
\r
6 trap "kill $!; ping_cancelled=true" SIGINT
\r
7 wait $! # Wait for the loop to exit, one way or another
\r
8 trap - SIGINT # Remove the trap, now we're done with it
\r
9 echo "Done pinging, cancelled=$ping_cancelled"
\r