Last active
April 29, 2016 03:19
-
-
Save lsongdev/332b80f24e7f203987eff11fc6765bd8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# example: | |
# | |
# curl -s https://gist.githubusercontent.com/song940/332b80f24e7f203987eff11fc6765bd8/raw/progressbar.sh | sh | |
# | |
function ProgressBar(){ | |
let max=$1 | |
let done=$2 | |
let left=$max-$done | |
let current=($done*100/$max*100)/100 | |
local fill=$(printf "%${done}s") | |
local empty=$(printf "%${left}s") | |
printf "\r [${fill// /#}${empty// /-}] ${current}%%" | |
} | |
for i in {1..70}; do | |
ProgressBar 70 $i | |
sleep 0.1 | |
done | |
printf "\nFinished!\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@wenshin 如果不输出换行符(\n)就是会在当前行输出,\r 可以回到当前行的开头。