I'm writing a bash script in which I read single characters from the input. I do so using read -n 1 -s
. -n 1
is to read only a single character; -s
is "silent" mode, in which the typed characters won't be visible.
The problem is, that when the currently executed command isn't read
(whenever some other commands in the bash script are being executed), the character gets displayed in the terminal.
This is the normal behaviour of a program in the terminal. To disable this, one normally disables the echo mode, for example using the termios library.
How can I achieve this in a bash script?
I prefer solutions in pure bash / Unix commands (without other scripting languages like python, perl etc.).
stty -echo
# Anything they type won't output here
stty echo
# Now it will
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With