从bash脚本的当前行清除所有文本 [英] Clear all text on current line from a bash script

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

问题描述

我如何能引起<大骨节病> CTRL <大骨节病> U 从bash脚本?

即我想删除一行光标左侧所有的字符,并把光标列0。

一个解决方法可以打印 \\ r ,其次是一些以清除光标的权利。

我不想清除整个终端屏幕。

更新:

我使用(在PHP)解决方案:

 回声MYDATA。 \\ 033 [0K \\ R;


解决方案

基本上你可以做这样的事情:

 时:; #做一个无限循环只是演示
    回声$ RANDOM#在这里打你的东西
    睡0.2
    tput的cuu1#向上移动光标一行
    埃尔输出#清除行
DONE

使用 tput的人了解更多信息。要查看的功能列表中使用男人的terminfo

How can I cause ctrl u from a bash script?

Ie I want to remove all characters left of cursor on a line, and put cursor in column 0.

A workaround could be printing \r, followed by something to clear right of cursor.

I don't want to clear the whole terminal screen.

Update:

The solution I use (in PHP):

echo 'mydata' . "\033[0K\r";

解决方案

Basically you can do something like this:

while :; do # an infinite loop just for demonstration
    echo "$RANDOM" # print your stuff here
    sleep 0.2
    tput cuu1 # move cursor up by one line
    tput el # clear the line
done

Use man tput for more info. To see the list of capabilities use man terminfo

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

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