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

查看:19
本文介绍了在 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 提供给您的 read 调用,如下所示:

Just supply -s to your read call like so:

$ read -s PASSWORD
$ echo $PASSWORD

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

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