Quote:> Is there any easy/standard way to get asterisks
> echo'ed backed for each character typed without writing an elaborate c
> program to do so?
I whipped up this in Bash. It could definitely be improved for ksh (by
using '[[ ]]' instead of '[ ]' and 'print' instead of 'echo' for improved
efficiency, for example), but the principle seems to work:
#!/bin/bash
newLine="$(echo X | tr 'X' '\015')"
crgRet="$(echo X | tr 'X' '\012')"
backSpace="$(echo X | tr 'X' '\010')"
Print='echo -e' # enables '\r' in Bash; you may not need this in your shell
getField ()
{
getFieldGeneric insecure
Quote:}
getSecureField ()
{
getFieldGeneric secure
Quote:}
getFieldGeneric ()
{
typeset newChar
typeset dispChar='*' # change this to display some other character
typeset secureField
Field=
while : ; do
stty -echo raw
newChar=$(dd if=/dev/tty bs=1 count=1 2>/dev/null)
stty -raw echo
if [ "x${newChar}x" = "x${newLine}x" -o \
"x${newChar}x" = "x${crgRet}x" ]; then
echo
break;
elif [ "x${newChar}" = "x${backSpace}x" ]; then
Field="${Field%?}"
secureField="${secureField%?}"
else
Field="${Field}${newChar}"
secureField="${secureField}${dispChar}"
fi
if [ "$1" = "secure" ]; then
$Print -n "\r${secureField} ${backSpace}"
else
$Print -n "\r${Field} ${backSpace}"
fi
done
Quote:}
getSecureField
echo "getSecureField got: \"${Field}\""
getField
echo "getField got: \"${Field}\""
Give it a burl!
Fred Surr
Melbourne