Link to home
Start Free TrialLog in
Avatar of Frédéric Métraux
Frédéric MétrauxFlag for Switzerland

asked on

Password as a parameter for a shell script

Hello,

I have a shell script that accepts parameters. One of them is a password and I would like not to enter the password as a parameter, as it appears in clear on the command line. The password should be typed by the user and if possible invisible on screen. How can I do this?

Thanks.
Avatar of tfewster
tfewster
Flag of United Kingdom of Great Britain and Northern Ireland image

#!/usr/bin/ksh
echo "Enter password"
trap "Sorry, Ctrl-C disabled" 2
stty -echo
read PW
echo $PW
stty echo
trap 2
Of course, you'll have noticed that the "trap" statement is wrong and you wouldn't normally echo the password back after taking steps to prevent it displaying on screen...
ASKER CERTIFIED SOLUTION
Avatar of tryno
tryno

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice script - filing it for future use ;-)

ornicar, does that answer your question? If so, please accept trynos comment as an  answer. If not, please post more information.
Avatar of Frédéric Métraux

ASKER

tryno's is nice. I'll accept his answer. But yours, tfwefters, deserves to be very simple and I prefer it for this reason, so I made a question for you.