Get Hidden Input from User.

HI All,

I want to take input from user on linux console...but i dont wnt it to be visible.. just like we type password for ssh or scp

Right now I am using "read" to take input from user but it also makes it visible when user type it.

read -ep "Dear User Please enter password : " pass

and on console user get this

Dear User Please enter password : hEllo

I dont wnt this hEllo world to be visible when user type it.

Thanks in advance.

regards
-kashif

Use -s option of read.

#!/bin/ksh
print -n "Enter password - "
stty -echo
read PASSWORD
stty echo

You can use read -s for hiding user input .

1 Like

can you plz give me complete syntax for read -s coz currently I am getting error for this command.

read -s "Enter Password" pass
line 3: read: `Enter Password': not a valid identifier
echo "enter passwd"
read -s    PASS
echo " U R password is $PASS"
read -s -p "Enter Password" pass

-s for 'secret'
-p for 'prompt'

Thanks all for replies. its working as I needed. But now requirement is slightly changed.

Instead of hidden input I am looking to print * for every word typed as password.

like

echo -n "Please Enter Password : "
read -p pass

and it looks like when user type password

Please Enter Password: hEllo

Now I want that when user type hEllo it should show "*****" for typed password.

like

Please Enter Password: *****

Thanks in advance.

Use this:

prompt="Enter password: "
sw=0
while [ "$sw" -eq 0 ]
do
        read -p "$prompt" -s -n 1 char
        if [[ $char == $'\0' ]]
        then
                sw=1
        fi

        prompt='*'
        password+="$char"
done
echo
unset sw