Created
August 22, 2017 22:23
-
-
Save gcoda/2340d3efe47f6e0de9fce046ca199bd6 to your computer and use it in GitHub Desktop.
Proper Ctrl + C on infinite bash loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#The exit status of a command that terminated because it received a signal shall be reported as greater than 128. | |
#For example if you interrupt a command with control-C the exit code will be 130, because SIGINT is signal 2 on Unix systems. So: | |
#source: https://unix.stackexchange.com/questions/42287/terminating-an-infinite-loop | |
while [ 1 ]; do | |
echo 1 #do the thing | |
sleep 1 | |
test $? -gt 128 && break; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment