How do I echo stars (*) when reading password with `read`?

后端 未结 10 859
死守一世寂寞
死守一世寂寞 2020-11-29 02:13

What do I need to do for code in Bash, if I want to echo *s in place of password characters (or even just hide the characters completely) when the user types so

10条回答
  •  被撕碎了的回忆
    2020-11-29 02:22

    stty -echo
    read something
    stty echo
    

    will stop user input being echoed to the screen for that read. Depending on what you are doing with prompts, you may want to add an extra echo command to generate a newline after the read.

提交回复
热议问题