Last active
October 8, 2015 20:09
-
-
Save cheuerde/03aa8be7a2ec6c70a8b0 to your computer and use it in GitHub Desktop.
Progress Bar in BASH
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
# Taken from here: http://stackoverflow.com/a/28044986/2748031 | |
#!/bin/bash | |
# 1. Create ProgressBar function | |
# 1.1 Input is currentState($1) and totalState($2) | |
function ProgressBar { | |
# Process data | |
let _progress=(${1}*100/${2}*100)/100 | |
let _done=(${_progress}*4)/10 | |
let _left=40-$_done | |
# Build progressbar string lengths | |
_fill=$(printf "%${_done}s") | |
_empty=$(printf "%${_left}s") | |
# 1.2 Build progressbar strings and print the ProgressBar line | |
# 1.2.1 Output example: | |
# 1.2.1.1 Progress : [########################################] 100% | |
printf "\rProgress : [${_fill// /#}${_empty// /-}] ${_progress}%%" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment