Operating System - HP-UX
1835271 Members
2303 Online
110078 Solutions
New Discussion

Entering passwords from a terminal

 
SOLVED
Go to solution
Doug Dell
Advisor

Entering passwords from a terminal

Hello Gang,

I have what I hope is a very simple question. How do I enter a password in a shell script and not have it displayed on the screen?

Thanks in advance, Doug

3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Entering passwords from a terminal

Hi Doug:

I have what I hope is a very simple answer.

#!/usr/bin/sh

trap 'stty echo; exit' 0 1 2 3 15


echo "Enter Password: \c"
stty -echo
read PASSWD
stty echo

The passwd is now in ${PASSWD}. Note the use of the trap; this is important because if your user hits Ctrl-C (intr), the terminal is restored to normal (echo) use. Man stty for details.

Regards, Clay




If it ain't broke, I can fix that.
Doug Dell
Advisor

Re: Entering passwords from a terminal

Hi Clay,

Geez, do I feel stupid. This was so simple. I tried it without the trap and it did just what you said. My terminal was messed up.

Thanks, Doug
A. Clay Stephenson
Acclaimed Contributor

Re: Entering passwords from a terminal

Hi Doug:

Making you feel stupid is a bonus service. I'm glad this worked for you.

Clay
If it ain't broke, I can fix that.