How to enter password as hidden characters in shell script

不言
Release: 2019-03-20 17:09:15
Original
5197 people have browsed it

This article introduces to you how to enter passwords in the form of hidden characters in shell scripts. Let’s take a look at the specific content.

How to enter password as hidden characters in shell script

Let’s first look at the command

read -s -p “Enter Password: ” pswd
Copy after login

How to use:

If you want to enter the password in the shell script. You probably don't want any characters entered by the user to be displayed on the screen. Use -s for silent mode. Characters entered using -s will not be echoed. For example, create a shell script named inputpwd.sh and add the following content.

$ vim inputpwd.sh
Copy after login
#!/bin/bash ### Input password as hidden charactors ### read -s -p "Enter Password: " pswd ### Print the value of pswd variable ### echo -e "\nYour password is: " $pswd
Copy after login

Let's execute the script and enter the password, you just enter the password and the characters will not be displayed on the screen. This only works with the /bin/bash shell, older shells (/bin/sh) will throw an error.

Let's execute the script and enter your password, you just enter your password and no characters will appear on the screen. This only works with /bin/bash shell, older shells (/bin/sh) will throw errors.

# chmod +x inputpwd.sh # ./inputpwd.sh Enter Password: Your password is: 9kjdfk329sksk
Copy after login

This article has ended here. For more other exciting content, you can pay attention to theLinux Tutorial Videocolumn of the PHP Chinese website! ! !

The above is the detailed content of How to enter password as hidden characters in shell script. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!