3

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"

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

boop
  • 7,413
  • 13
  • 50
  • 94
  • lookup `tput` http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html –  Feb 17 '15 at 15:26
  • This can help: [Deleting echo line in bash](http://stackoverflow.com/a/10321364/1983854). It suggests using either spaces or _use some terminal escape sequences to delete the old text (not portable)_ – fedorqui Feb 17 '15 at 15:29

1 Answers1

3

You can use the clr_eol terminal capability for this.

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

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

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148