#!/bin/sh
if [[ $# != 1 ]];
then
echo $0 basepath;
echo ;
fi
path=$1;
declare -a statearray;
(find $path -type f -print)| while read line;
do
#echo "----"
echo $line;
#echo "----"
ftype=`file -b "$line"`;
ftype=`echo "$ftype" | cut -f 1 -d " " `;
echo "$ftype";
let statearray["$ftype"]++;
done;
for type in "${!statearray[@]}";
do
echo $type : ${statearray["$type"]};
done
先說腳本的功能:
統計目錄下各個文件類型數
出現問題
ISO-8859 文件類型不能統計
出現
statearray: bad array subscript錯誤
去看一些文檔,但是並沒有發現shell數組中對關聯數組下標有嚴格限制,一般都說是字符串;
測試
發現
array["ISO-8859"]=1
bash: array["ISO-8859"]: bad array subscript
但是"ISO-8859" 也是字符串
所以還是有些疑惑!明天繼續問大牛..