覆盖终端上的最后一行 [英] Overwrite last line on terminal

查看:57
本文介绍了覆盖终端上的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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

它将读取desc变量,直到通过空行为止.之后,我想阅读其他内容.

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,并使用\e[K:

In your example you delete the text at the same line. When you want to return to the previous line use \e[1A, and to clear that line, use \e[K:

echo 'Old line'
echo -e '\e[1A\e[Knew line'

要排成N行时,请使用\e[<N>A

这篇关于覆盖终端上的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆