庆典最后覆盖终端线 [英] bash overwrite last terminal line
问题描述
我的bash脚本看起来如下:
My bash-script looks as following:
echo "Description:"
while [ $finishInput -eq 0 ]; do
read tmp
desc="$desc"$'\n'"$tmp"
if [ -z "$tmp" ]; then
finishInput="1"
fi
done
echo -n "Maintainer:"
read maintainer
直到空行传递它读给递减变种。在那之后,我想其他的东西阅读。
It reads to the desc var until a empty line is passed. After that, i want to read in other stuff.
当我执行当前脚本,它看起来是这样的:
When executing my current script it looks like this:
Description:
Line 1
Line 2
Maintainer:
我想覆盖的最后一个空行维护者。
I would like to overwrite the last empty line with the "Maintainer:".
我搜索了一个解决方案,但只发现了其中像
I searched for a solution but only found suggestions which were like
echo -n "Old line"
echo -e "\r new line"
它可以停留在该行并将其覆盖。这是不可能在我的情况。
which stays on the line and overwrites it. This is not possible in my case.
推荐答案
只需使用\\ E [1A
。
在您的例子中,你在同一行中删除文本:
In your example you delete the text at the same line:
$ echo -n "Old line"; echo -e "\e[0K\r new line"
new line
当您想返回到previous行使用\\ E [1A:
When you want to return to the previous line use \e[1A:
$ echo "Old line"; echo -en "\e[1A"; echo -e "\e[0K\r new line"
new line
当你想要去N行了,使用 \\ E [< N方式> A
When you want to go N lines up, use \e[<N>A
.
这篇关于庆典最后覆盖终端线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!