如果有多个sizeof *d
,tput cuu 1 && tput el
的效果非常好。但是,如何替换由echo
打印的行?
read
以上示例输出:
echo "First line..."
read -p "Press any key to overwrite this line... " -n1 -s
tput cuu 1 && tput el
echo "Second line. read replaced."
我希望最终结果是:
First line... Second line. read replaced.
答案 0 :(得分:2)
您的代码未将光标移动到第0列。
一个简单的解决方案是在read
使用tput sc
打印提示之前保存光标位置。
阅读用户输入后,您可以使用tput rc
恢复光标位置。
您的代码现在应该看起来像这样。
echo "First line..."
tput sc
read -p "Press any key to overwrite this line... " -n1 -s
tput rc 1; tput el
echo "Second line. read replaced."
希望这有帮助。