Shell第二次作业

1、将密码文件的每一行作为元素赋值给数组

root@sy zuoye]# cat 2_1.sh 
#/bin/bash
while read line
do
	a+=($line)
	
done < /etc/passwd
echo ${a[*]}

2、使用关联数组统计密码文件中用户使用的不同类型shell的数量

[root@sy zuoye]# cat 2_2.sh 
#/bin/bash
index=`awk -F : '{print($NF)}' /etc/passwd`
declare -A array
for i in $index
do
	let array[$i]++
done
for i in ${!array[*]}
do
	echo $i=${array[$i]}
done

3、使用关联数组按扩展名统计指定目录中文件的数量

[root@sy zuoye]# cat 2_3.sh 
#/bin/bash
index=`ls |awk -F . '{print($NF)}'`
declare -A array
for i in $index
do
	let array[$i]++
done
for i in ${!array[*]}
do
	echo $i=${array[$i]}
done

你可能感兴趣的:(shell,linux,运维,服务器)