Clear all text on current line from a bash script

岁酱吖の 提交于 2019-12-14 02:44:47

问题


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";

回答1:


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



来源:https://stackoverflow.com/questions/24319932/clear-all-text-on-current-line-from-a-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!