Have you ever written a bash script that does a lot of stuff and runs for a long time? If so, I am sure that soon after you run it, you thought: I wish I had implemented a counter to understand how long is it left for this thing to finish!

The following function will write a progress bar on your stdout!

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: