#! /bin/bash
declare -A shells
while read line
dotype=`echo$line| awk -F: '{print $7}'`
let shells[$type]++
done < /etc/passwd
for i in ${!shells[*]}doecho"$i 的数量为 ${shells[$i]}"
done
7、使用关联数组按扩展名统计指定目录中文件的数量
#!/bin/bash
read -p "pleace input filename:" filename
declare -A array
for i in `ls$filename| fgrep '.'| cut -d .-f 2`
do
let array[$i]++
done
for i in ${!array[*]}doecho"$i: ${array[$i]}"
done