I just saw this code somewhere.
It allows the user to enter his password and change it to an asterisk/star.
But it doesn't recognize the backspace key.
The code thinks that the backspace is part of the password.
What should I do to make it recognize the backspace?
And can someone explain this code to me?
Especially the IFS, the options of read, and the $'\0'
Thanks!
Here is the code.
\#!/bin/bash
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
echo
echo "Done. Password=$password"
passwd
command in a terminal session. In any event, when you enter your password the characters are not echoed to screen for security reasons, so the script you've copied in your question accomplishes nothing extra.