Frédéric Métraux
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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ornicar, does that answer your question? If so, please accept trynos comment as an answer. If not, please post more information.
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.
echo "Enter password"
trap "Sorry, Ctrl-C disabled" 2
stty -echo
read PW
echo $PW
stty echo
trap 2