如何让 bash 脚本要求输入密码? [英] How to make bash script ask for a password?

查看:15
本文介绍了如何让 bash 脚本要求输入密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于如何让 bash 脚本要求输入密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆