From ee6aa3a34601952c0802ffa1459f1da0890646f8 Mon Sep 17 00:00:00 2001 From: Nathan Jones Date: Sat, 4 Jul 2015 01:07:54 +1200 Subject: [PATCH] handle backspace in get_pass --- pwd.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pwd.sh b/pwd.sh index 92e9dd8..ca78ea1 100755 --- a/pwd.sh +++ b/pwd.sh @@ -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