Created
June 21, 2019 15:23
-
-
Save pbatey/25c55b8695a262969fe91d59140f492b to your computer and use it in GitHub Desktop.
Bash script to display progress (to stderr) by counting lines from stdin.
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 | |
# | |
# Displays progress (to stderr) by counting lines from stdin. | |
# | |
# Usage: <command> | progress.sh <expected-line-count> > <file> | |
# | |
total=$(( ${1:-0} )) | |
number=0 | |
while read line; do | |
number=$(( number+1 )) | |
if [ $total -gt 0 ]; then | |
percent=$(( number*100/total )) | |
>&2 echo -en " $percent%\r" | |
fi | |
echo $line | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment