使用数组取出系统中每一种shell的数量

[root@qls /service/scripts/day12]# cat array-2.sh
#!/bin/bash
#声明关联数组
declare -A  Array_Shells
#批量赋值
while read line
do
    #赋值  
    #Type=$(echo $line | awk -F: '{print $NF}')
    # /bin/bash  这个是索引   对应的值  次数 数字
    let Array_Shells[${line##*:}]++
done < /etc/passwd
#批量打印结果
for i in ${!Array_Shells[*]} 
do
    echo -e "Shell: $i\t\tCount: ${Array_Shells[$i]}"
done
[root@qls /service/scripts/day12]# sh array-2.sh
Shell: /sbin/nologin		Count: 24
Shell: /bin/sync		Count: 1
Shell: /bin/bash		Count: 23
Shell: /sbin/shutdown		Count: 1
Shell: /sbin/halt		Count: 1
[root@qls /service/scripts/day12]# wc -l /etc/passwd 
50 /etc/passwd
[root@qls /service/scripts/day12]# awk -F: '{print $NF}' /etc/passwd | sort | uniq -c 
     23 /bin/bash
      1 /bin/sync
      1 /sbin/halt
     24 /sbin/nologin
      1 /sbin/shutdown

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值