1

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";
Jonny
  • 15,955
  • 18
  • 111
  • 232
  • I found a working answer here: http://stackoverflow.com/a/5861713/129202 so I guess I could delete my question as duplicate :-P – Jonny Jun 20 '14 at 04:31

1 Answers1

5

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

Aleks-Daniel Jakimenko-A.
  • 10,335
  • 3
  • 41
  • 39