For example after doing apt-get update, it shows
Reading package lists... 82% with the percentage changing in the same line.
How is that achieved? Is it possible to use it in a bash script?
For example after doing apt-get update, it shows
Reading package lists... 82% with the percentage changing in the same line.
How is that achieved? Is it possible to use it in a bash script?
Terminals understand escape sequences to move the cursor around, change the text color and other actions. These escape sequences are recorded in the termcap and terminfo databases as they differ between terminal types (altough most terminal types today mostly implement the same escape sequences).
You can record the full output of an application with the script utility.
script -c 'apt-get update' apt-get.script
apt-get keeps things simple: it only uses the control character carriage return (known as CR, Ctrl+M, \r, …) which moves the cursor to the beginning of the current line.
if you haven't output new line yet (e,g: used -n in echo command) , the command:
echo -e "\r\033["
will do the trick.