回车前,清除行 [英] Clear line before carriage return

查看:146
本文介绍了回车前,清除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印一个进步 - 在同一行。所以我用一个回车。问题是我的进步不是的增加的=>这意味着第一次印刷可能是处理:富酒吧巴兹和下打印可能是处理:富。用一个简单的回车的问题是,在第二打印将<青霉>重叠的由第一打印。我希望你明白我想说什么..

I want to print a progress - in one line. So I use a carriage return. The problem is my progress isn't increasing => this means the first print could be Processing: Foo Bar Baz and the next print could be Processing: Foo . The problem with a simple carriage return is that the second print would be overlayed by the first print. I hope you understand what I want to say..

printf "\r Processing: $x"
# or
echo -en "\r Processing: $x"

所以我的问题是:我怎样才能delte当前行的内容,并与回车覆盖它

So my question is: How can I delte the content of the current line and overwrite it with carriage return?

推荐答案

您可以使用 clr_eol 终端能力这一点。

You can use the clr_eol terminal capability for this.

printf '\r%s Processing: %s' "$(tput el)" "$x"

注意我是如何移动的printf 格式字符串变量了的?一般不用在格式字符串变量棒

Notice how I moved the variable out of the printf format string? In general do not stick variables in the format string.

这篇关于回车前,清除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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