bash – 如何用`read`读取密码时回显星星(*)?

当用户使用read键入内容时,如果我想要echo * s代替密码字符(或者甚至完全隐藏字符),我需要为Bash中的代码做什么?
正如Mark Rushakoff指出的,读-s将禁止在提示符处键入的字符的回显。您可以将此功能用作此脚本的一部分,以为每个键入的字符回显星号:
#!/bin/bash
unset password
prompt="Enter Password:"
while IFS= read -p "$prompt" -r -s -n 1 char
do
    if [[ $char == $'\0' ]]
    then
        break
    fi
    prompt='*'
    password+="$char"
done
echo
echo "Done. Password=$password"

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...