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