Languages
[Edit]
EN

Bash - read password in script without displaying characters

10 points
Created by:
Wade
562

In this short article, we would like to show how to read password in Bash without displaying characters in the terminal.

Quick solution:

Where:

  • -s prevents against typed characters displaying,
  • -p "Password: " prints Password:  message,
  • password is the name of the variable that will store the typed password.

 

Practical example

Edit

Paste the following code into your bash script (e.g. password.sh file).

Example result:

Reading password in Bash script without displaying characters.
Reading password in Bash script without displaying characters.

Alternative titles

  1. Bash - disable echoing for typed password in shell script
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join