Given this bash script:
stty -echo
echo $(stty)
reset() {
stty echo
echo $(stty)
exit
}
trap reset int
read -s
sleep 10
I expected the echo option to be enabled, but after pressing ctrlc it is still disabled, even though I have ran stty echo
(as you can see in the output by the reset
function).
As @KamilCuk has noticed in the comments,
read
saves the configuration and restores it when the process exists. That results in modifications done whileread
was running being discarded. The solution is to restore the defaults before runningread
and redoing them afterread
finishes.@JonathanLeffler also noted that
Explaination:
Which I think is the more proper solution, as the
stty
may run in no-echo mode by default.