Jonny
Jonny

Reputation: 16308

Clear all text on current line from a bash script

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

Upvotes: 1

Views: 2564

Answers (1)

Aleks-Daniel Jakimenko-A.
Aleks-Daniel Jakimenko-A.

Reputation: 10653

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

Upvotes: 5

Related Questions