Friday, November 21, 2008

How to read password from bash script.

i wrote a bash script to read the username and password of the user through the terminal.

read -p "Username: " uname
read -p "Password: " pass;


But normally the terminal will display all text that we enter in to it. So i got the output below.



Username: aneesh
Password: CAPSLOCK

I want to avoid password being displayed. So I modified the above script as below.

ead -p "Username: " uname
stty -echo
read -p "Password: " pass;
echo
stty echo

echo " The entered username and password are $uname and $pass"

Now it works fine..

No comments:

Followers