如何关闭终端中的回声? [英] How do I turn off echo in a terminal?

查看:48
本文介绍了如何关闭终端中的回声?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Bourne shell 脚本并输入如下密码:

I'm writing a Bourne shell script and have a password input like this:

echo -n 'Password: '
read password

显然,我不希望密码被回显到终端,所以我想在读取期间关闭回显.我知道使用 stty 可以做到这一点,但我会在阅读手册页的同时为了社区的利益提出这个问题.;)

Obviously, I don't want the password being echoed to the terminal, so I want to turn off echo for the duration of the read. I know there's way to do this with stty, but I'll ask the question for the benefit of the community whilst I go read the manpage. ;)

推荐答案

stty_orig=`stty -g`
stty -echo
echo 'hidden section'
stty $stty_orig

这篇关于如何关闭终端中的回声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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