使用“read”时如何清除 Bash 中的用户输入?
我有这个代码处于无限循环中:
read -a output
echo ${output[@]}
当代码运行时,屏幕可能看起来像这样:
Hello, World # line where value was given to output (I want this gone)
Hello, World # echoed output
[] # <-- cursor waiting for next input
有没有办法清除用户输入值的行?就像完全摆脱它一样(不仅仅是将行更改为空白,这仍然会在所需的输出中留下间隙)?
I have this code in an infinite loop:
read -a output
echo ${output[@]}
When the code runs the screen might look like this:
Hello, World # line where value was given to output (I want this gone)
Hello, World # echoed output
[] # <-- cursor waiting for next input
Is there a way to clear the line where the user inputs the value? Like, as in get rid of it totally (not just changing the line to whitespace that will still leave a gap in the desired output)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
tput
与cuu1
和dl1
功能结合使用。Use
tput
with thecuu1
anddl1
capabilities.为什么不直接删除
echo ${output[@]}
呢?由于您没有引用数组变量,因此这似乎与使用tput
hax 的结果相同。Why not just remove the
echo ${output[@]}
? Since you're not quoting your array variable, this seems to be the same result as if you were to usetput
hax.