3

When we download something or install software via Terminal, we always see a number show the progress to us.
The number is changed, but it still in the same line.
How can I do in the bash?

I'm a new basher, help!

android_su
  • 1,637
  • 4
  • 21
  • 30
  • http://bash.cyberciti.biz/guide/A_progress_bar_%28gauge_box%29 - 2 seconds on google (this one is a fancy TUI variety). – oakad Dec 04 '13 at 08:05
  • 2
    Use a carriage return http://stackoverflow.com/questions/2388090/how-to-delete-and-replace-last-line-in-the-terminal-using-bash – Sanghyun Lee Dec 04 '13 at 08:08
  • 1
    [My answer](http://stackoverflow.com/a/1508589/45249) to [How can I erase the current line printed on console in C ?](http://stackoverflow.com/q/1508490/45249) may help. It is about [VT100 escape codes](http://www.climagic.org/mirrors/VT100_Escape_Codes.html). In bash, `printf "\x41"` outputs `A`. – mouviciel Dec 04 '13 at 08:13
  • 1
    I was just about to comment about ANSI escape codes :-) – anishsane Dec 04 '13 at 08:14

2 Answers2

5

The trick is to use \r instead of \n at the end of the line:

echo -n " 50% complete."$'\r'; sleep 1; echo "100% complete."
Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
1

Use echo -n.

More informations on this other post.

Community
  • 1
  • 1
Andrea
  • 6,032
  • 2
  • 28
  • 55