#!/bin/bash

# $1 is current value
# $2 is max value - if reached it will be reset
increment()
{
  ret=0;
  if (( $1 == $2 )); then ret=0; else let ret=$1+1; fi
  echo $ret
}

#########################################################
## Main
#########################################################
iterations=100
i=0
# cursor index
j=0
k=0
cursor=(\| \/ \- \\) 

while (( i < $iterations ))
do
# echo cursor
echo -n "  ${cursor[j]}"
# increment cursor index
j=`increment $j 3`

echo -n " "
# print progress
l=0
while ((l < k))
do
echo -n "="
let l=l+1
done
# clear previous progress line (otherwhise 
# you always see the whole after first iteration)
while (( l <= 50 ))
do
echo -n " ";
let l=l+1
done

# jump back to beginning of line 
echo -ne "\r"
let i=i+1

k=`increment $k 50`

# stop script for x seconds to show the cursor long enough
sleep 0.2s
done

echo -e "\nfinished"
