I learned from https://unix.stackexchange.com/a/230568/674 thatping
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
...
dash
orzsh
instead ofbash
orksh
). I remember a discussion that was detailing the differences between shells in this regard, but I suck at googling and the only thing I could find is this which is explaining it as if it were the obvious, expected behavior. – Nov 01 '18 at 10:48