如何使用bash删除和替换终端中的最后一行? [英] How to delete and replace last line in the terminal using bash?

查看:18
本文介绍了如何使用bash删除和替换终端中的最后一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 bash 中实现一个显示经过秒数的进度条.为此,我需要擦除屏幕上显示的最后一行(命令清除"擦除所有屏幕,但我只需要擦除进度条的行并用新信息替换它).

I want to implement a progress bar showing elapsed seconds in bash. For this, I need to erase the last line shown on the screen (command "clear" erases all the screen, but I need to erase only the line of the progress bar and replace it with the new information).

最终结果应如下所示:

$ Elapsed time 5 seconds

然后在 10 秒后我想将这句话(在屏幕中的相同位置)替换为:

Then after 10 seconds i want to replace this sentence (in the same position in the screen) by:

$ Elapsed time 15 seconds

推荐答案

echo a回车

seq 1 1000000 | while read i; do echo -en "
$i"; done

来自人回声:

-n     do not output the trailing newline
-e     enable interpretation of backslash escapes


     carriage return

这篇关于如何使用bash删除和替换终端中的最后一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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