Let see how to read the password without echoing back
First, create a file named ” User.sh ” using the following command
$ touch User.sh
Now open ” User.sh ” in the text editor
$ nano User.sh
Now write the below bash script into ” User.sh “
#!/bin/bash echo "Enter Username : " # read username and echo username in terminal read username echo "Enter Password : " # password is read in silent mode i.e. it will # show nothing instead of password. read -s password echo echo "Your password is read in silent mode."
Note: Here ‘ -s ‘ is used to read passwords because it will read passwords in silent mode.
Now save the above bash script and run ” User.sh ” by following the command
$ chmod +x ./User.sh $ ./User.sh
Output :
Here, we can see clearly that the above script will read username as well as password but it does not echo the password.
Bash Scripting – Bash Read Password without Echoing back
Generally, you can see on the login page, whenever we type a password either it show dot (•) or asterisk (*) instead of a password. They do so because to protect our system or account. In such a case, the login page read the password and in place of the password, it will show a dot or asterisk. And in some cases, a dot or asterisk also may not appear it means it displays nothing in place of a password.