Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert the entered password to * in the Shell script

Shulou Source: shulou.com Published: 2022-06-03 08:43:08 11月15日 Update

This article mainly introduces how to convert the input password into * in the Shell script, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.

If you need to write a paragraph that interacts with the user and needs to enter some sensitive information (such as user password, License, etc.), then the information entered by the user will be displayed on the screen by using printf+read directly, which is not in line with information security and is not professional enough for the customer experience, so you need to convert the password entered by the user to *, as follows:

Please input your passwd:1234

Modified to:

Please input your passwd:****

So how to achieve it? please read on.

#! / bin/shgetchar () {stty cbreak-echo dd if=/dev/tty bs=1 count=1 2 > / dev/null stty-cbreak echo} printf "Please input your passwd:" while:; do ret= `getchar` if [x$ret = x] Then echo break fi str= "$str$ret" printf "*" doneecho "Your password is: $str" Thank you for reading this article carefully. I hope the article "how to convert the entered password into *" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Input password user article information script security not enough professional value interest at the same time customer screen way more friends style knowledge ribbon Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple Docker MySQL Shulou Technology