Bash progress bar

Bash progress bar

Have you ever written a bash script that does a lot of stuff and runs for a long time? While running it, sooner or later, you probably thought: I wish I had implemented a counter to understand how far is the script is, how long it has been running for and more importantly, how long is it left for this thing to finish!

The following function will write a progress bar on your stdout and give you lots of useful info! The ETA will get more accurate as the script progresses.

All you need to do is to have a start time in epoch, a counter and the number that the counter needs to reach. Be careful to redirect the stdout and stderr of your script somewhere else, like a log file, or the bar will not be visible and your script output will be polluted by the bar.

For example have a look at the following script:

vernon plumbing