linuxbashscripting

Hiding user input on terminal in Linux script


I have bash script like the following:

#!/bin/bash

echo "Please enter your username";
read username;

echo "Please enter your password";
read password;

I want that when the user types the password on the terminal, it should not be displayed (or something like *******) should be displayed). How do I achieve this?


Solution

  • Just supply -s to your read call like so:

    $ read -s PASSWORD
    $ echo $PASSWORD