vishnupriya
vishnupriya

Reputation: 7

password hiding in shell

I am new to shell scripting . i want to make the password not visible when we type password ..can you please suggest me on this

echo "enter your password"

read pass

if [ "$pass" != "" ]

then

echo "thank you "

else

echo "invalid password"

exit

fi

Upvotes: 0

Views: 332

Answers (3)

SudoAgent
SudoAgent

Reputation: 36

read -sp pass

this should help.

Upvotes: 1

tvm
tvm

Reputation: 3449

Alternatively, if you issue in your bash prompt:

help read

You will find out that you can use a switch.

 -s                do not echo input coming from a terminal

Thus simply using read -s pass will solve your problem.

Upvotes: 2

Alexander L. Belikoff
Alexander L. Belikoff

Reputation: 5721

Use

# turn echo off
stty -echo

...

# turn echo back on
stty echo

Upvotes: 1

Related Questions