- Load a web page
- Copy/paste two pieces of information into Excel
- Repeat ...
- ... 1700+ times
Luckily I was able to script the whole process so it took me about 30 minutes of building the script and then about 2.5 hours of letting the script run in the background.
During that 2.5 hours, I found myself wondering "Gosh, is that thing done yet!?" and wishing that I had some way to tell how close it was to being done. So I used that time to build a small BASH function that will give a progress bar in your terminal window to show the progress of a given script.
To use it, you just need to paste the function into the top of your script and then in your for or while loop, add the line below and it will build the bar for you.
showBar $<counter variable> $<total iterations>
And here is the code:
#!/bin/bash
function showBar {
percDone=$(echo 'scale=2;'$1/$2*100 | bc)
barLen=$(echo ${percDone%'.00'})
bar=''
fills=''
for (( b=0; b<$barLen; b++ ))
do
bar=$bar"="
done
blankSpaces=$(echo $((100-$barLen)))
for (( f=0; f<$blankSpaces; f++ ))
do
fills=$fills"_"
done
clear
echo '['$bar'>'$fills'] - '$barLen'%'
}
The example below shows how to include the showBar function in a for loop:
for (( i=0; i<=245; i++ ))I wouldn't be at all surprised if there is a better, more elegant way to accomplish this, but this is how I did it.
do
showBar $i 245
done
Cheers!

