To make password/input text invisible?

All,

My script is
-----------

#cat pass.sh
password=123
echo -n "Enter pass:"
read pass
if [ $pass = $password ]; then
echo "Correct password"
else
echo "Wrong password"
fi

When i run this script, text(password) which i'm entering is visible in screen
-----------------------------------------------------------------------

$ sh pass.sh
Enter pass:123
Correct password
$

I want to make it invisible when i enter the text... How can i do that.? Anybody help on this...

 
read -sp "password: " pass
 
echo $pass
1 Like

Another way with "stty":

$ cat noEchoPass.sh
sttySettings=`stty -g`
echo "Password: "
stty -echo
read pass
stty "${sttySettings}"
echo "pass: [${pass}]"
$ ./noEchoPass.sh
Password:
pass: [test]
1 Like

Thank you itkamaraj & felipe.vinturin

---------- Post updated 12-03-11 at 11:31 AM ---------- Previous update was 12-02-11 at 05:07 PM ----------

Hi,

#cat test1.sh
read -sp "password: " pass
echo $pass

This is not woking in solaris. It shows error like.

# sh test1.sh
test1.sh: -sp: is not an identifier

It would work in bash, but I guess you are using plain, old sh.

If it's just a simple solution you want, the stty -echo option from felipe.vinturin is fine.