Operating System - HP-UX
1834127 Members
2044 Online
110064 Solutions
New Discussion

Entering a password from the shell

 
SOLVED
Go to solution

Entering a password from the shell

Hello HP Experts,

How can I enter a password in a shell script and not have it appear on the screen. I'm sure that this is very simple but I have not been shell scripting very long.

Thanks in advance for your help,
Steve
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Entering a password from the shell



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


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

That should do it.
If it ain't broke, I can fix that.
Sridhar Bhaskarla
Honored Contributor

Re: Entering a password from the shell

Hi Steve,

Following is a simple case.

printf "Enter your password:"
stty -echo
read password
stty echo
echo your password is $password

(or do whatever you want to with $password)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: Entering a password from the shell

Hi again,

I should mention that the stty -echo will APPEAR to work just fine without the trap statement. The trap returns the terminal to a normal state upon receipt of an n'rupt or hangup. The stty command actually alters the tty device for all processes connected to that device.
If it ain't broke, I can fix that.
Sridhar Bhaskarla
Honored Contributor

Re: Entering a password from the shell

Hi Steve,

stty -echo is the key and Clay made an excellent point about 'trap'.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try