0

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

Community
  • 1
  • 1
vishnupriya
  • 7
  • 1
  • 4

3 Answers3

2

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.

tvm
  • 3,263
  • 27
  • 37
1

Use

# turn echo off
stty -echo

...

# turn echo back on
stty echo
Alexander L. Belikoff
  • 5,698
  • 1
  • 25
  • 31
1
read -sp pass

this should help.

SudoAgent
  • 36
  • 1