如何让 bash 脚本要求输入密码?脚本、输入密码、bash

2023-09-07 09:31:55 作者:丶糾結旳青春

我想用密码保护程序的执行.如何要求用户输入密码而不回显?

I want to secure the execution of a program with a password. How can I ask the user to enter a password without echoing it?

推荐答案

stty_orig=$(stty -g) # save original terminal setting.
stty -echo           # turn-off echoing.
IFS= read -r passwd  # read the password
stty "$stty_orig"    # restore terminal setting.