Terminal input hidden after read -s interrupt

Pressing Ctrl-C while waiting for input from the read -sp operation returns the operation back to the command line, but the data entry is hidden, as if read -s still running.

Example

 #!/bin/sh sig_handler() { echo "SIGINT received" exit 1 } trap "sig_handler" SIGINT read -sp "ENTER PASSWORD: " password echo echo $password 

which is usually done as follows:

 $~ ./example.sh ENTER PASSWORD: password $~ text -bash: text: command not found 

but if you press Ctrl-C on ENTER PASSWORD, you will get

 $~ ./example.sh ENTER PASSWORD: SIGINT received $~ -bash: text: command not found 

where text or any other next command is not displayed as input until you update with reset .

How can you return the text to normal input after receiving a SIGINT? read -p "ENTER PASSWORD: " password not required for obvious security reasons.

+5
source share
1 answer

Add stty sane to your signal handler so that it restores the terminal to its default state:

 sig_handler() { echo "SIGINT received" stty sane exit 1 } 
+4
source

Source: https://habr.com/ru/post/1263696/


All Articles