0

I have the following code in bash

read -p "Enter your ID: " ID
unset PASSWORD
prompt="Enter Password:"
  while IFS= read -p "$prompt" -r -s -n 1 char
  do
    if [[ $char == $'\0' ]]
       then
         break
    fi
prompt='*'
PASSWORD+="$char"
done

Practically this code ask to user for a password, and each word type down in terminal shows as * but i have the problem that when I need to delete a character this code it does not takes the backspace, instead shows the backspace as any other character, so I would like to this code does not takes the backspace as character and it erased the words type down in terminal.

Rashwan L
  • 38,237
  • 7
  • 103
  • 107
shaveax
  • 458
  • 6
  • 16
  • Echoing each character as an asterisk is a bad idea to begin with. You leak your user's password length to anyone who peeks over your user's shoulder, or the password length may be recorded in terminal logs. And your user is screwed if, say, the password is revealed to be only three characters long. – 4ae1e1 Dec 27 '15 at 09:08

1 Answers1

0

You could use -e option with your read like:

read -e -p ...
SMA
  • 36,381
  • 8
  • 49
  • 73