Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent typed characters from being displayed (like disabling "echo" attribute in termios)

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.).

like image 301
leemes Avatar asked Jun 11 '12 20:06

leemes


1 Answers

stty -echo
# Anything they type won't output here
stty echo
# Now it will
like image 97
Jay Avatar answered Oct 25 '22 15:10

Jay