Have You ever wondered how to read password to the variable in the script without echoing it to the screen?
This is quite simple and can be written in just few lines:

oldSTTY=$(stty --save)
stty -echo
read -p "Password: " PASSWD; echo
stty $oldSTTY

1: You save all current settings of the terminal
2: You disable echoing of input characters to the screen
3: You read password into PASSWD variable
4: You restore all your terminal settings as it was before

As I said it is very simple and straightforward, isn’t it?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.