使用数组统计,用户shell的类型和数量
Posted 透明车窗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用数组统计,用户shell的类型和数量相关的知识,希望对你有一定的参考价值。
#!/bin/bash
declare -A shells (定义关联数组shells)
while read ll (读取/etc/passwd,ll为变量)
do
type=`echo $ll | awk -F: ‘{print $7}‘` (type为变量,切割ll后的变量)
let shells[$type]++
done < /etc/passwd
for i in ${!shells[@]}
do
echo "$i ::::: ${shells[$i]}"
done
~
[root@localhost ~]# bash tj2.sh
/sbin/nologin ::::: 17
/bin/sync ::::: 1
/bin/bash ::::: 3
/sbin/shutdown ::::: 1
/sbin/halt ::::: 1
以上是关于使用数组统计,用户shell的类型和数量的主要内容,如果未能解决你的问题,请参考以下文章