I want to show a progress bar during a bash operation in a specific format something similar to the following:
[###########](40%)
after update it should become
[###############](50%)
and then similarly reach upto 100%
Is there any way to achieve this
I wrote the following bash program but i don't know how to show the percentage in this on same line:
#!/bin/bash
{
echo -n "["
for ((i = 0 ; i <= 100 ; i+=6)); do
sleep 0.05
echo -n "###"
done
echo -n "]"
echo
}
Let's assume that a certain number of operations are being performed in a loop and after the completion of each operation, I want to report some progress. I don't want to install pv
or any other utilities that does not come with default Ubuntu 12.04
installation.
Using tput commands
https://github.com/extensionsapp/progre.sh
Create 24 percent progress:
progreSh 24
There is a lot of options, you may save and restore cursor position like this:
This is one of the vt100 terminal controlling commands, one of the commands in list:
http://www.cse.psu.edu/~kyusun/class/cmpen472/11f/hw/hw7/vt100ansi.htm
or just use \r to move cursor to the beginning of the line and redraw bar each time
The \r is more portable and will work across most UNIXes (unsure about MacOS)
In your example:
You can use
pv
as the progress bar:Let's use
echo -n '...' $'\r'
to print a carriage return:It makes the cursor move to the beginning of the line to keep printing.
Output is as follows, always in the same line:
You can do something like below:
sleep is Just to simulate the time require by application to install.
Using the above syntax You can do as below
Hope this helps!!