I wrote this, using an awk command I found:
RUNS=10
CUR=1
PREFIX=" 1/10 ($((${CUR} * 100 / ${RUNS}))%)"
echo "" | awk '{printf("%'+`expr 2 + ${RUNS} + ${#PREFIX}`+'s\r[", "]'${PREFIX}'")}' ;
for CUR in {1..`expr $RUNS`..1}; do
echo -n '▒'
sleep .1
done
echo ""
output:
[▒▒▒▒▒▒▒▒▒▒] 1/10 (10%)
I understand, that the progress bar update make use of the carriage return from the echo command and just overwrites the blanks. Sadly I'm not familiar with awk (nor sed for that matter).
However I wonder, if I can update CUR and the % in PREFIX as well as the current length of the PREFIX string in order to update the awk output (during runtime of cause).
My Cnf is:
$ sw_vers && awk --version && bash --version | grep bash && brew info zsh | grep zsh:
ProductName: Mac OS X
ProductVersion: 10.15.4
BuildVersion: 19E287
awk version 20070501
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
zsh: stable 5.8 (bottled), HEAD
(even if I'm using zsh, I'd prefer a bash or pure POSIX approach)