1.点号进度显示code 1
#!/bin/sh
#输出"."进度条函数,兼容bsh、ksh、bash
#首先trap 1 2 3 15信号,重要
trap 'kill $BG_PID;echo;exit' 1 2 3 15
function dots
{
stty -echo >/dev/null 2>&1
while true
do
echo -e "./c"
sleep 1
done
stty echo
echo
}
#---------------------------------------------
# 主程序开始
#---------------------------------------------
#首先使dots函数后台运行
dots &
BG_PID=$!
#开始程序主体,本例中执行休眠10秒
#注意必要时--8
2.井号进度显示code 2
#!/bin/sh
abort() {
printf "/033[m/n"
exit
}
#donothing,justsimulatetimeconsume.
idle() {
i=1
sum=`date +%S`
sum=`expr $sum /* $sum | cut -b1`
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]"
echo ##########################$pos1 -le $pos2
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
echo ######################$pos1 -le $pos2
done
printf "/033[m/n"
echo "done"
}
printf "###proc1 100 10 ###hit ENTER to continue "
if read a;then
proc 1 100 10
fi