Skip to content

Instantly share code, notes, and snippets.

@foresta
Created October 23, 2022 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foresta/1c2fd61c93faf08c17a0b423a2640b94 to your computer and use it in GitHub Desktop.
Save foresta/1c2fd61c93faf08c17a0b423a2640b94 to your computer and use it in GitHub Desktop.
bash progress bar
#!/bin/bash
progress_bar() {
current=$1
total=$2
progress=$(($current * 100 / ${total}))
bar="$(yes '#' | head -n ${progress} | tr -d '\n')"
if [ -z "$bar" ]; then
bar='_'
fi
printf "\r[%-100s] (%d/%d)" ${bar} ${current} ${total}
}
echo "[Start]"
total=100
for i in $(seq 1 ${total}); do
progress_bar $i $total
sleep 0.05
done
echo ""
echo "[Finish]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment