Bash Read Password without echoing back

Bash Read Password

Bash Read Password – In this Bash Tutorial, we shall learn to read username and password from user, with Password being not echoed back to shell.

Bash Read Username and Password without echoing


We shall use read command with following options,

read -p PROMPT <variable_name>  displays PROMPT without a new line and echoes input read from user, character by character. The input is read to bash variable. This optionp  is suitable for reading Username.

read -sp PROMPT <variable_name>  displays PROMPT without a new line and reads input from user in silent mode (does not echo back user input). The input is read to variable. These optionss,p  are suitable for reading Password.


Example Bash Shell Script to Read Username and Password

Note : An empty echo is provided after reading Password becauseread -sp  reads input in silent mode and does not echo back input including new line. However pressing enter key after password makes the input be loaded to password variable.

Example to Read Password with * echoed back to Shell


Recommended Reading : Bash Read User Input


Conclusion :

In this Bash Tutorial – Bash Read Password, we have learnt to read password without echoing back the password or masking it with some other characters.