1.編寫腳本sumid.sh,計(jì)算/etc/passwd文件中的第10個(gè)用戶和第20個(gè)用戶的UID之后
[root@centos7 ~]# vim sumid.sh
#!/bin/bash
a=`head -n10 /etc/passwd|tail -n1|cut -d: -f3`
b=`head -n20 /etc/passwd|tail -n1|cut -d: -f3`
let c=a+b
echo $c
unset a b c
[root@centos7 ~]# chmod +x sumid.sh
[root@centos7 ~]# ./sumid.sh
43
2.編寫腳本sumspace.sh,傳遞兩個(gè)文件路徑作為參數(shù)給腳本,計(jì)算這兩個(gè)文件中所有空白行之和
[root@centos7 ~]# vim sumspace.sh
#!/bin/bash
file1=$1
file2=$2
a=`grep "^$" $file1|uniq -c`
b=`grep "^$" $file2|uniq -c`
let c=a+b
echo $c
unset a b c file1 file2
[root@centos7 ~]# ./sumspace.sh file3 file4
9
3.編寫腳本sumfile.sh,統(tǒng)計(jì)/etc,/var,/usr目錄中共有多少個(gè)一級子目錄和文件
[root@centos7 ~]# vim sumfile.sh
#!/bin/bash
num1=`ls /etc |wc -l`
num2=`ls /var |wc -l`
num3=`ls /usr |wc -l`
let sum=num1+num2+num3
echo $sum
unset num1 num2 num3 sum
[root@centos7 ~]# ./sumfile.sh
324