shell 输入密码显示星号

Posted on Posted in 百态人生
文章目录[隐藏]

shell 输入密码显示星号

getchar(){
    stty cbreak -echo
    dd if=/dev/tty bs=1 count=1 2>/dev/null
    stty -cbreak echo
}
printf "Please input your passwd:"

while : ;do
    ret=`getchar`
    if [ x$ret = x ]; then
        echo
        break
    fi
    str="$str$ret"
    printf "*"
done
echo "Your password is : $str"
» 转载请注明来源:若我若鱼 » shell 输入密码显示星号

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × two =