Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active July 25, 2022 16:16
Show Gist options
  • Save rsperl/c9eeef0dc88d8598173494aa02d3436c to your computer and use it in GitHub Desktop.
Save rsperl/c9eeef0dc88d8598173494aa02d3436c to your computer and use it in GitHub Desktop.
do not echo stdin to stdout #shell #snippet
#!/bin/bash
# show prompt without a newline
echo -n "Password:"
# Turn off echo
stty -echo
# Read what the user typed
read passwd
# Turn echo back on
stty echo
# instead of turning echo off and back on, you can also
# save the current tty settings with
# stty_orig=$(stty -g)
# turn echo off, then restore the tty settings with
# stty $stty_orig
echo "you entered: $passwd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment