Last active
August 29, 2015 14:06
-
-
Save kakwa/ecccbe71bfb82c4d0250 to your computer and use it in GitHub Desktop.
Quick and dirty progress bar function in shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
print_progress_bar(){ | |
percent=$1 | |
width=$2 | |
width=$(( ${width} - 10 )) | |
barlen=$(( ${width} * ${percent} / 100 )) | |
voidlen=$(( ${width} - ${barlen} )) | |
bar=`printf %${barlen}s |tr " " "="` | |
void=`printf %${voidlen}s` | |
if [ `printf ${percent} | wc -c` -eq 1 ] | |
then | |
percent=" ${percent}" | |
fi | |
printf "\r[${bar}${void}] (${percent}%%)" | |
} | |
counter=0 | |
while [ $counter -ne 101 ] | |
do | |
print_progress_bar ${counter} 80 | |
counter=$(( $counter + 1 )) | |
sleep 0.1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment