Q:
I am accepting the password from the user using 'read' command.
How can I make the password not to appear on the screen when the user is typing.
A:
# save the old terminal settings
oldmodes=`stty -g`
# disable terminal 'echo' - blind typing
stty -echo
# read user input/password
read password
# restore 'old' terminal settings
stty $oldmodes
NOTE:
Yet Another Useful Tip [YAUT] by olded [Ed]:
# readkey: This function saves the current terminal settings and
# sets the terminal to raw mode with the unix stty command. Retrieve
# 1 character with the dd command and reset original terminal settings
# with stty before returning the character to calling script.
function readkey {
local anykey oldstty
oldstty=`stty -g`
stty -icanon -echo min 1 time 0
anykey=`dd bs=1 count=1 <&0 2>/dev/null`
stty $oldstty
echo $anykey
} # end read_key
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.