print
stty -echo
read -r pw?"Enter password: "
stty echo
print
does the job. But, is there a way to have an asterisk appear for each
password character typed?
It is easy in C putting the terminal in cbreak mode, but in ksh seems
impossible.
I am using ksh93
Thanks
read will only return after getting a newline. The -r option only
affects how backslash-newline sequences are to be treated, it does
not do a raw read.
You could either:
function savetty
{
SAVETTY=$(stty -g </dev/tty)
}
function rawtty
{
stty raw -echo </dev/tty
}
function cookedtty
{
stty ${SAVETTY:-cooked} </dev/tty
}
function getpass
{
typeset
savetty
rawtty
typeset -n passwd=${1:-PASSWD}
typeset ans
while :
do
ans=`dd if=/dev/tty count=1 bs=1 2>/dev/null`
case $ans in
$'\n') break;;
$'\b') [[ -n $passwd ]] && {
passwd="${passwd%?}"
print -n "\b \b"
}
;;
*) passwd="${passwd}${ans}";print -n "*";;
esac
((${#passwd}>8)) && { print -n "\a";break; }
done
cookedtty
}
[[UNTESTED]]
or create a builtin
Dan Mercer
Opinions expressed herein are my own and may not represent those of my employer.
If the OS you're using has a facility equivalent to mapchan, try that.
I use e.g.
[set up traps to unmap channel on interrupt]
mapchan -f hide.map
read -r password
mapchan -n
where hide.map contains:
# Erase, newline, cr, and ^G are not hidden because the shell may emit them.
output
1 '*'
2 '*'
3 '*'
4 '*'
5 '*'
6 '*'
7 7
8 8
9 '*'
10 10
11 '*'
12 '*'
13 13
14 '*'
...
255 '*'
John
--
John DuBois spc...@armory.com. KC6QKZ http://www.armory.com./~spcecdt/