Skip to main content
Post Closed as "Duplicate" by Stéphane Chazelas shell-script
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Source Link
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.