lee*_*mes 7 bash terminal scripting termios
我正在编写一个bash脚本,其中我从输入中读取单个字符.我这样做read -n 1 -s
.-n 1
是只读一个字符; -s
是"静音"模式,其中键入的字符将不可见.
问题是,当当前执行的命令不执行时read
(无论何时执行bash脚本中的某些其他命令),该字符都会显示在终端中.
这是终端中程序的正常行为.要禁用此功能,通常会禁用回显模式,例如使用termios库.
我怎样才能在bash脚本中实现这一点?
我更喜欢纯bash/Unix命令中的解决方案(没有其他脚本语言,如python,perl等).
Jay*_*Jay 16
stty -echo
# Anything they type won't output here
stty echo
# Now it will
Run Code Online (Sandbox Code Playgroud)