Why does this script keep running after receiving SIGINT?
2
votes
2
answers
1088
views
I learned from https://unix.stackexchange.com/a/230568/674 that
ping
will exit with 0 after receiving SIGINT, which allows a bash script containing a ping
command to continue running instead of exiting.
I have a script with similar behavior:
#!/bin/bash
while true; do
sudo -S sleep 4;
echo $?
sudo -k;
done
When I run it, I type Ctrl-C when it asks me for password, and the script doesn't exit, but continue running. The only difference is that sudo
upon receiving SIGINT exits with 1 not 0. So I wonder why the bash script doesn't exit but continue running? Thanks.
$ ./test.sh
[sudo] password for t:
1
[sudo] password for t:
1
[sudo] password for t:
1
...
Asked by Tim
(106430 rep)
Nov 1, 2018, 12:37 AM
Last activity: Mar 25, 2020, 08:10 AM
Last activity: Mar 25, 2020, 08:10 AM