How to get a password from a shell script without echoing How to get a password from a shell script without echoing bash bash

How to get a password from a shell script without echoing


Here is another way to do it:

#!/bin/bash# Read Passwordecho -n Password: read -s passwordecho# Run Commandecho $password

The read -s will turn off echo for you. Just replace the echo on the last line with the command you want to run.


A POSIX compliant answer. Notice the use of /bin/sh instead of /bin/bash. (It does work with bash, but it does not require bash.)

#!/bin/shstty -echoprintf "Password: "read PASSWORDstty echoprintf "\n"


One liner:

read -s -p "Password: " password

Under Linux (and cygwin) this form works in bash and sh. It may not be standard Unix sh, though.

For more info and options, in bash, type "help read".

$ help readread: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]Read a line from the standard input and split it into fields.  ...  -p prompt output the string PROMPT without a trailing newline before            attempting to read  ...  -s                do not echo input coming from a terminal