Skip to content

Instantly share code, notes, and snippets.

@kakwa
Last active August 29, 2015 14:06
Show Gist options
  • Save kakwa/ecccbe71bfb82c4d0250 to your computer and use it in GitHub Desktop.
Save kakwa/ecccbe71bfb82c4d0250 to your computer and use it in GitHub Desktop.
Quick and dirty progress bar function in shell
#!/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