使用“读取”时,如何在Bash中清除用户输入?

时间:2011-01-19 01:59:57

标签: bash input clear

我将此代码置于无限循环中:

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

有没有办法清除用户输入值的行?就像完全摆脱它一样(不仅仅是将线条改为空白,仍然会在所需的输出中留下间隙)?

2 个答案:

答案 0 :(得分:2)

tputcuu1dl1功能结合使用。

echo "foobar42"
echo "$(tput cuu1)$(tput dl1)baz123"

答案 1 :(得分:0)

为什么不删除echo ${output[@]}?由于您没有引用数组变量,这似乎与您使用tput hax的结果相同。