不求甚解

此博客为个人学习之用,如与其他作品雷同,纯属巧合。

导航

unzip解压进度条函数

Posted on 2022-04-12 18:41  三年三班王小朋  阅读(533)  评论(0编辑  收藏  举报

unzipfun

#!/bin/bash
#auther by wangxp

function unzipfun
{
if test $# -ne 2;then
echo 'unzipfun $filename $filedir'
exit 1
fi
if test ! -f $1;then
echo "$1 is not exist"
exit 1
fi
if test ! -d $2;then
echo "$2 is not exist"
exit 1
fi
if test -z "`rpm -qa unzip`";then
echo "unzip is not installed"
exit 1
fi
echo "$1 解压至目录 $2"
unzip -qo $1 -d $2 >/dev/null 2>&1 &
index=0
total=`unzip -l $1|tail -n 1|awk '{print $2}'`
str=''
while [ $index -lt 100 ]
do
current_t=`ls -aRl $2|grep ^[d,-]|wc -l`
current_d=`ls -Rl $2|grep ^d|wc -l`
current=$[$current_t-2*$current_d-2]
for (( i=$index; i< $[$current*100/$total]; i++ ))
do
str+='#'
done
sleep 0.5
index=$[$current*100/$total]
printf "[%-100s]\t[%3d%%]\r" $str $index
done
echo -e  "\n解压完成"
}