Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop output to screen

Status
Not open for further replies.

maxcrook

Programmer
Jan 25, 2001
210
GB
Ive have a script that will only be accessed when inputting a password - however i dont want to see the password as I type it - is there a way of not setting the echo so that you dont see the output of what your typing in.
If that makes sense!
 
You mean this?

Code:
...
echo "please enter password: \c"
stty -echo
read pw
stty echo
echo
if [ ${pw} = "secret" ]
then
 # OK
 ...
else
 echo "wrong password"
fi

But you wouldn't want the password in clear text inside the script - kind of silly, because people need read+execute access to a file if they want to run the script... So if they know where to look, the'll know the password.

HTH,

p5wizard
 
hi,

Or this variant
Code:
# save terminal setting    
OLDSTTY=$(stty -g 2>/dev/null)
#in case of abnormal termination, restore terminal setting automatically
trap "stty $OLDSTTY" 1 2 3 6 14 15
#change terminal setting to blind mode
stty -icanon -echo min 1 time 0 2>/dev/null
#get password in blind mode
read PASSWORD?"Enter your password : "
#print a line feed
print
#restore terminal setting before continuing
stty $OLDSTTY 2>/dev/null
#continue to get things in visible mode
read login?"Enter your login : "
 
Thanks folks utilised bits of both.
Great stuff.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top