使用“read"读取密码时如何回显星号(*)? [英] How do I echo stars (*) when reading password with `read`?
本文介绍了使用“read"读取密码时如何回显星号(*)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户使用 <代码>读取?
推荐答案
正如 Mark Rushakoff 所指出的,read -s
将抑制在提示符处键入的字符的回显.您可以将该功能用作此脚本的一部分,为输入的每个字符回显星号:
As Mark Rushakoff pointed out, read -s
will suppress the echoing of characters typed at the prompt. You can make use of that feature as part of this script to echo asterisks for each character typed:
#!/bin/bash
unset password
prompt="Enter Password:"
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $' ' ]]
then
break
fi
prompt='*'
password+="$char"
done
echo
echo "Done. Password=$password"
这篇关于使用“read"读取密码时如何回显星号(*)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文