#!/bin/sh
abort() {
printf "\033[m\n"
exit
}
# do nothing, just simulate time consume.
idle() {
i=1
sum=`date +%S`
sum=`expr $sum \* $sum | cut -b 1`
sum=`expr $sum \* 10`
while [ $i -le $sum ]; do
i=`expr $i + 2 `
trap abort 2
done
}
proc() {
begin=$1
end=$2
row=$3
pos1=`expr $begin + 1`
pos2=`expr $end - 1`
mid=`echo "($begin+$end)/2-2" |bc`
printf "\033[2J"
printf "\033[${row};${begin}H["
printf "\033[${row};${end}H]"
while [ $pos1 -le $pos2 ]; do
pro=`echo "scale=0; ($pos1 - $begin)*100/($pos2-$begin)" | bc`
if [ $pos1 -gt $mid ]; then
printf "\033[7m\033[${row};${mid}H$pro%%\033[${row};${pos1}H:"
else
printf "\033[m\033[${row};${mid}H$pro%%\033[7m\033[${row};${pos1}H:"
fi
pos1=`expr $pos1 + 1`
idle
trap abort 2
done
printf "\033[m\n"
echo "done"
}
# call subroutine
printf "### proc 1 80 10 ### hit ENTER to continue "
if read a; then
proc 1 80 10
fi
printf "### proc 25 55 10 ### hit ENTER to continue "
if read a; then
proc 25 55 20
fi
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。