Skip to content

Instantly share code, notes, and snippets.

@imjeen
Created November 22, 2019 09:16
Show Gist options
  • Save imjeen/3f47d54c184442ddb4c62811beb2b110 to your computer and use it in GitHub Desktop.
Save imjeen/3f47d54c184442ddb4c62811beb2b110 to your computer and use it in GitHub Desktop.
Enter password width asterisk (*) on the fly
#!/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