在Linux脚本中将用户输入隐藏在终端上 [英] Hiding user input on terminal in Linux script

查看:54
本文介绍了在Linux脚本中将用户输入隐藏在终端上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的bash脚本:

I have bash script like the following:

#!/bin/bash

echo "Please enter your username";
read username;

echo "Please enter your password";
read password;

我希望当用户在终端上键入密码时,不应显示该密码(或应显示诸如*******之类的内容).我该如何实现?

I want that when the user types the password on the terminal, it should not be displayed (or something like *******) should be displayed). How do I achieve this?

推荐答案

仅向您的读取调用提供-s,就像这样:

Just supply -s to your read call like so:

$ read -s PASSWORD
$ echo $PASSWORD

这篇关于在Linux脚本中将用户输入隐藏在终端上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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