Created
October 23, 2022 11:07
-
-
Save foresta/1c2fd61c93faf08c17a0b423a2640b94 to your computer and use it in GitHub Desktop.
bash progress bar
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/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