In article <785fad$qr
...@winter.news.rcn.net>,
"Joseph Suriol" <tigl
...@usa.net> writes:
> The script
> 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
damer...@uswest.net
Opinions expressed herein are my own and may not represent those of my employer.