When installing things in Linux I often see stdout change after printing eg. there might be a counter showing installation progress that starts at 1% and goes up to 100%. How is this done? When I write C programs and I print something using printf, I can't change it afterwards - if I type 1%, it stays that way. How is it done? Is there a different function I have to use?
Asked
Active
Viewed 111 times
1 Answers
1
\r brings you back to the beginning of the line without issuing the \n to go to the next line. Use this to overwrite text on the screen to build progress bars, etc.
See:
-
You will probably find `\r` to have significant limitations and most likely will want to control the cursor with either `tput` or the ansi-escape sequences following `\033`. See: [**ANSI Escape Sequences: Colours and Cursor Movement**](http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html). E.g.: copy and paste the following at the command line: `( for i in $(seq 1 100); do printf "\033[s\033[u %3d %% \033[u" "$i"; sleep 0.1; done )` – David C. Rankin Oct 04 '14 at 01:55