Hiding user input on terminal in Linux script
for a solution that works without bash or certain features from read
you can use stty
to disable echo
stty_orig=$(stty -g)
stty -echo
read password
stty $stty_orig
Just supply -s to your read call like so:
$ read -s PASSWORD
$ echo $PASSWORD
Update
In case you want to get fancy by outputting an *
for each character they type, you can do something like this (using andreas' read -s
solution):
unset password;
while IFS= read -r -s -n1 pass; do
if [[ -z $pass ]]; then
echo
break
else
echo -n '*'
password+=$pass
fi
done
Without being fancy
echo "Please enter your username";
read username;
echo "Please enter your password";
stty -echo
read password;
stty echo