1. 旋转指针
#!/bin/sh
proc() {
c0='-'
c1='\'
c2='|'
c3='/'
begin=$1
end=$2
row=$3
pos1=`expr $begin + 1`
pos2=`expr $begin + 5`
printf "\033[2J"
while [ $begin -le $end ]; do
index=`expr $begin % 4`
pro=`echo "scale=0; ${begin}*100/$end" | bc`
eval printf \"'\033[${row};${bos1}H$c'$index '$pro%% '\"
begin=`expr $begin + 1`
done
echo "done"
}
# call subroutine
proc 0 102 20
2. 进度条
#!/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
阅读(412) | 评论(0) | 转发(0) |