handle backspace in get_pass

This commit is contained in:
Nathan Jones 2015-07-04 01:07:54 +12:00
parent c3139e4a1e
commit ee6aa3a346
1 changed files with 12 additions and 3 deletions

15
pwd.sh
View File

@ -21,14 +21,23 @@ fail () {
get_pass () {
# Prompt for a password.
unset password
password=''
prompt="${1}"
while IFS= read -p "${prompt}" -r -s -n 1 char ; do
if [[ ${char} == $'\0' ]] ; then
break
if [[ ${char} == $'\0' ]] ; then
break
fi
if [[ ${char} == $'\177' ]]; then
if [[ -z "${password}" ]]; then
prompt=''
else
prompt=$'\b \b'
password="${password%?}"
fi
else
prompt='*'
password+="${char}"
fi
done
if [ -z ${password+x} ] ; then