Consider this script:
#!/bin/bash
echo "hi there $(whoami)"
[ "`whoami`" = "root" ] || {
exec sudo -u root "$0" "$@"
echo "this is never called"
}
read -s -p "enter stuff: " stuff
echo "answer: $stuff"
If I run it as user lars and enter woohoo, then I get the following output:
hi there lars
hi there root
enter stuff:
answer: woohoo
However, if I ctrl-c while the script is waiting for my read input, then I get into a weird state. The console seems to be stuck in silent mode. The problem does not occur if I omit the -s (= Silent mode) option.
Do you have any idea what the exact problem is here? How can I make the script behave properly if someone presses ctrl-c during the input.
I am running bash 4.3.30.