Created
November 22, 2019 09:16
-
-
Save imjeen/3f47d54c184442ddb4c62811beb2b110 to your computer and use it in GitHub Desktop.
Enter password width asterisk (*) on the fly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
$USER="anonymous" | |
echo | |
unset password | |
prompt="Please input the $USER's Password: " | |
while IFS= read -p "$prompt" -r -s -n 1 char | |
do | |
if [[ $char == $'\0' ]] ; then | |
break | |
fi | |
# backspace | |
if [[ $char == $'\177' ]] ; then | |
prompt=$'\b \b' | |
password="${password%?}" | |
fi | |
prompt='*' | |
password+="$char" | |
done | |
echo | |
echo "Your password is: $password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment