For the sake of argument, here is an example ksh script called "getpw" that I have in my bag of tricks. I did not write this, but saw it somewhere and saved it. My apologies to the author. Perhaps it can be adapted to bash, or at least studied to learn some new tricks
#! /usr/bin/ksh
exec 4>/dev/tty
function getpass
{
typeset prompt=$1
typeset backspace=$(echo \\b\\c)
typeset enter=$(echo \\r\\c)
typeset savesetting=$(stty -g)
typeset keystroke password n i reading result
n=0
echo "${prompt}"\\c >&4
stty -echo -icrnl -icanon min 1 time 0
reading=1
while ((reading)) ; do
keystroke=$(dd bs=1 count=1 2>/dev/null)
case $keystroke in
$enter) reading=0
;;
$backspace) if ((n)) ; then
echo "${backspace} ${backspace}"\\c >&4
((n=n-1))
fi
;;
*) echo \*\\c >&4
data[n]=$keystroke
((n=n+1))
;;
esac
done
stty "$savesetting"
echo >&4
result=""
i=0
while ((i<n)) ; do
result="${result}${data}"
((i=i+1))
done
echo $result
return 0
}
final=$(getpass "password: ")
echo the password is $final
exit 0