Site icon New Generation Enterprise Linux

Taming Terminal Echo: Control Input Display with `stty`

Quick Tip

Taming Terminal Echo: Control Input Display with `stty`

Challenge: Sometimes, especially in scripting or when dealing with sensitive input, you need to temporarily disable or control the echoing of characters typed into the terminal. This can prevent unintended display of passwords or control output formatting.

The Solution: The `stty` command is your friend here. To disable echoing, use `stty -echo`. To re-enable it, use `stty echo`.

# Temporarily disable echoing stty -echo # Do your sensitive operation (e.g., read password) read -p "Enter password: " password # Re-enable echoing stty echo # Now you can use the $password variable securely echo "Password received."

Why it works: The `stty` command manipulates terminal line discipline settings. The `-echo` flag tells the terminal driver not to send typed characters back to the display, while `echo` restores this behavior.

Pro-Tip: You can also use `stty raw` to disable almost all terminal input processing, useful for low-level character handling. Remember to restore settings with `stty sane` when done.

Linux Tips & Tricks | © ngelinux.com | 6/2/2026

0 0 votes
Article Rating
Exit mobile version