As Mark Rushakoff pointed out, read -s
will suppress the echoing of characters typed at the prompt. You can make use of that feature as part of this script to echo asterisks for each character typed:
#!/bin/bash
unset password
prompt="Enter Password:"
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'' ]]
then
break
fi
prompt='*'
password+="$char"
done
echo
echo "Done. Password=$password"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…