#!/bin/bash #**************************************************** #Date: 2020-06-25 #Author: Damon Ye #FileName: countshell.sh #Description:The test script #**************************************************** declare -A ArrayForShell while read EachLine do ArrayIndex=`echo $EachLine | awk -F: ‘{print $7}‘` let ArrayForShell[$ArrayIndex]++ done < /etc/passwd echo "######${!ArrayForShell[@]}######" 数组索引 echo "######${#ArrayForShell[@]}######" 数组元素的个数 echo "######${ArrayForShell[@]}######" 数组元素 for i in ${!ArrayForShell[@]} 数组索引的个数 == for循环执行的次数,这就是关联数组的遍历。 do echo "$i ::::: ${ArrayForShell[$i]}" done
[root@localhost package]# bash countshell.sh ######/sbin/nologin /bin/sync /bin/bash /sbin/shutdown /sbin/halt###### ######5###### ######37 1 2 1 1###### /sbin/nologin ::::: 37 /bin/sync ::::: 1 /bin/bash ::::: 2 /sbin/shutdown ::::: 1 /sbin/halt ::::: 1
https://blog.csdn.net/a54925171/article/details/102275447
使用关联数组统计文件/etc/passwd中用户使用的不同类型shell的数量
原文:https://www.cnblogs.com/ytdyz/p/13191936.html