如何删除和使用bash替换最后一行在终端? [英] How to delete and replace last line in the terminal using bash?
本文介绍了如何删除和使用bash替换最后一行在终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现显示在bash经过秒的进度条。对于这一点,我需要擦除显示在屏幕上的最后一行(命令清除删除所有画面,但我需要擦除只进度条线,并与新的信息替换它)。
最终的结果应该是这样的:
$经过的时间5s
然后在10秒后我想通过更换这句话(在屏幕同一位置):
$经过时间15秒
解决方案
回声\\ r
回车 序列1百万|而读我;做回声-en\\ R $ I; DONE
从人的回声:
-n不输出其后的换行符
-e使反斜杠逃逸间pretation\\ r回车
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).
Final result should look like:
$ Elapsed time 5 seconds
Then after 10 seconds i want to replace this sentence (in the same position in the screen) by:
$ Elapsed time 15 seconds
解决方案
echo a carriage return with \r
seq 1 1000000 | while read i; do echo -en "\r$i"; done
from man echo:
-n do not output the trailing newline
-e enable interpretation of backslash escapes
\r carriage return
这篇关于如何删除和使用bash替换最后一行在终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文