Simple bash script for getting password-style user input

Here’s a little script for reading a ‘password’ field using dots for the typed characters.

#!/bin/bash -p

old_settings=$(stty -g)
trap 'stty $old_settings' EXIT HUP

echo -n "Enter Password: "
stty raw -echo
ichr=.
value=
oifs="$IFS"
IFS=
while [[ $ichr != "" ]]; do
    read -n1 ichr
    [[ -n $ichr ]] && echo -n '.'
    value="$value$ichr"
done
IFS="$oifs"
stty -raw echo
echo
echo "Value: '$value'"