Tuesday, December 5, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  13] [ 0]  / answers: 1 / hits: 114732  / 3 Years ago, wed, june 9, 2021, 5:24:37

Long time i am searching for this, i would like to know is it possible to pass passwords in a shell script? Many of the answers returned with no. Recently i read an article stating that how to pass passwords in a shell script. I have tried that, but it doesn't seem to work. This is the link. Can anyone checkitout and revert back? Also pls say me is there a way to pass passwords in a shell script? If no pls say me how linux gets the input for the password?

More From » bash


By "entering passwords", you likely mean entering data without being visible for the user.

(suggested by geirha) When using bash, you can use the -s option to prevent typed characters from being displayed:

read -p "Password please: " -s pass

Alternatively, change the behavior of the terminal to hide typed characters with stty -echo (disable echo). After reading the password with the shell built-in read into a variable (in the below example, $pass), turn it back on with stty echo. Because the new line from Enter is hidden to, you've to print a newline to get future output on a new line.

stty -echo
read -p "Password please: " pass
stty echo
printf '

read and printf are shell built-ins. stty is provided by the coreutils package which is installed by default. That means that this snippet is very portable.

Note: the -p option is not standard, but from bash. If you need to display a prompt in other shells, use:

printf "Password please: "
stty -echo
read pass
stty echo
printf '


[#44826] Friday, June 11, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 197
Total Questions: 113
Total Answers: 112

Location: Hungary
Member since Wed, Nov 9, 2022
1 Year ago
tresein questions
Tue, Jun 28, 22, 17:57, 1 Year ago
Sun, Apr 3, 22, 07:11, 2 Years ago
Thu, Feb 3, 22, 18:03, 2 Years ago
Sat, May 13, 23, 13:00, 7 Months ago