Imagine you are writing a shell script that requires the user to input confidential information, lets say a password.
The user wont feel comfortable if the password is echoed on the screen like a simple text. If you ever used expect interactive scripting, you know for sure this kind of problem.
Don’t worry, its amazingly easy to perform this trick and stop echoing whatever the user types on the screen.
Simply add the following line to your script:
stty -echo
and you are done. The stty output will go offline. Let’s see an example:
#!/bin/bash
echo Hello
stty -echo
# do what ever you want to do
echo 'I slept with your girlfriend'
stty echo
echo Bye
exit 0;
That’s it! Just remember to put it back to normal with the following command:
stty echo
Also, it would be helpful for you to read the whole man page for stty.
$ man stty