23,223
社区成员
发帖
与我相关
我的任务
分享
#!/bin/bash
if [ $# -lt 1 ];then
echo "calculate current dir"
else
dir=$1
echo "calculate $1"
cd $dir
if [ $? -ne 0 ];then
exit 0
fi
fi
function findtype
{
local ch=1
local str=""
local ft_str="$1"
ret=""
# echo "calculate $1"
while ( [ "$str" != "$ft_str" ] && [ "$ret" = "" ] )
do
str=`echo $ft_str|tail -c$ch`
#echo "check $str ch=$ch"
ret=`echo $str|grep '\.?*'`
ch=`expr $ch + 1`
done
#echo "get $ret"
}
strs=`ls`
if [ "$strs" = "" ];then
echo "empty"
exit 0
fi
filenum=0
#echo "presort:"
for name in $strs
do
#echo "$name"
farr[$filenum]="$name"
filenum=`expr $filenum + 1`
done
#sort file by type
i=0
filestop=`expr $filenum - 1`
echo "filenum:$filenum"
while [ $i -lt $filestop ]
do
j=`expr $i + 1`
while [ $j -lt $filenum ]
do
findtype ${farr[$i]}
cmpstr=$ret
findtype ${farr[$j]}
#echo "cmp $ret $cmpstr"
if [[ "$ret" < "$cmpstr" ]];then
tmp=${farr[$i]}
farr[$i]=${farr[$j]}
farr[$j]=$tmp
fi
j=`expr $j + 1`
done
i=`expr $i + 1`
done
#end sort
#printsort
#echo "after sort:"
#for (( i = 0 ; i < filenum ; i++))
#do
# echo ${farr[$i]}
#done
#end print
typenum=0
first=0
for (( i = 0 ; i < filenum ; i++))
do
findtype ${farr[$i]}
if [ $first -eq 0 ];then
pretype=$ret
first=`expr $first + 1`
typenum=1
elif [ "$ret" = "$pretype" ];then
typenum=`expr $typenum + 1`
elif ([ "$pretype" = "" ]);then
echo "get other count:$typenum"
typenum=1
pretype=$ret
else
echo "get $pretype count:$typenum"
typenum=1
pretype=$ret
fi
done
if [ "$ret" = "$pretype" ];then
if [ "$ret" = "" ];then
echo "get dir count:$typenum"
else
echo "get $ret count:$typenum"
fi
fi