#!/bin/bash
# helper
if [ -z ${1} ] || [ -z ${2} ] || [ "--help" == "${1}" ]; then
echo
echo "Usage: $0 [speed in second] [how many cycles] [cursorup] [bash clear]"
echo
echo "[cursorup]: 0, no tput cuu1; 1, yes tput cuu1"
echo "[bash clear]: 0, tput clear; 1, clear; command for each cycle"
echo "[bash clear]: 2, tput clear; 3, clear; command for each echo"
echo
exit 1
fi
# parameters
pos=0
sec=$1
how=$2
cur=$3
bas=$4
# test
clr='tput clear'
cuu='tput cuu1'
# function
clearEcho ()
{
ori=${1}
num=$(( ori + 1 ))
if [ $bas -eq $ori ]; then
$clr
else
if [ $bas -eq $num ]; then
clear
fi
fi
if [ $bas -eq $ori ] || [ $bas -eq $num ]; then
echo cycle: $pos
fi
}
# main
while [ $pos -lt $how ]
do
clearEcho 0
for i in $(echo "| / - \\")
do
clearEcho 2
echo $i
if [ $cur -gt 0 ]; then
$cuu
fi
sleep $sec
done
let pos++
done