Site icon New Generation Enterprise Linux

Taming Terminal Echo: Controlling Input Display with `stty`

Quick Tip

Taming Terminal Echo: Controlling Input Display with `stty`

Challenge: Sometimes, you need to input sensitive information into a command or script, and you don’t want the characters to be echoed back to the terminal for security or aesthetic reasons. This is common when prompting for passwords or when running automated scripts.

The Solution: The `stty` command is your friend for controlling terminal behavior. Specifically, `stty -echo` will disable input echoing, and `stty echo` will re-enable it.

stty -echo; read -p "Enter sensitive data: " sensitive_data; stty echo; echo "You entered: $sensitive_data"

Why it works: The `stty -echo` command instructs the terminal driver to not display characters as they are typed. The `read` command then captures the input without it appearing on screen. Finally, `stty echo` restores the default behavior so subsequent input is displayed normally.

Pro-Tip: Combine this with `read -s` (silent) for an even more secure password input, as `-s` also prevents the input from being displayed.

Linux Tips & Tricks | © ngelinux.com | 5/28/2026

0 0 votes
Article Rating
Exit mobile version