7

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

1 Answer 1

16
stty -echo # Anything they type won't output here stty echo # Now it will 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.