Skip to main content
1 of 2
Vi.
  • 6k
  • 7
  • 41
  • 75

How to make this loop Ctrl+C-interruptible?

# wait for host to become online while true; do ping host -c 1 -w 3 > /dev/null && break; sleep 1 done 

When I press Ctrl+C, the ping receives it and exits with exit code 1 (the same as if host down). How do I do this correctly?

Workaround: sleep 1 || break and pressing ^C twice.

Vi.
  • 6k
  • 7
  • 41
  • 75