In this short article, we would like to show how to read password in Bash without displaying characters in the terminal.
#!/bin/bash read -s -p "Password: " password
-sprevents against typed characters displaying,
-p "Password: "prints
passwordis the name of the variable that will store the typed password.
Paste the following code into your bash script (e.g.
#!/bin/bash read -s -p "Password: " password echo if [ "$password" = 'secret_password' ] then echo "User authenticated..."; else echo "Typed incorrect password!"; fi read