Reputation: 45665
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.).
Upvotes: 7
Views: 4926
Reputation: 3305
stty -echo
# Anything they type won't output here
stty echo
# Now it will
Upvotes: 16