当前位置: 技术问答>linux和unix
linux shell 脚本
来源: 互联网 发布时间:2017-04-30
本文导语: #!/bin/bash mypath=`echo $PATH | sed 's/:/ /g'` count=0 for director in $mypath do check='ls $director' for item in $check do count=$[ $count + 1 ] ...
#!/bin/bash
mypath=`echo $PATH | sed 's/:/ /g'`
count=0
for director in $mypath
do
check='ls $director'
for item in $check
do
count=$[ $count + 1 ]
done
echo $director - $count
count=0
done
~
以上是统计$PATH目录下文件的个数,以下是执行结果
[root@rac1 ~]# ./test3
/usr/kerberos/sbin - 2
/usr/kerberos/bin - 2
/usr/local/sbin - 2
/usr/local/bin - 2
/sbin - 2
/bin - 2
/usr/sbin - 2
/usr/bin - 2
/usr/X11R6/bin - 2
/root/bin - 2
我哪里错了么?
mypath=`echo $PATH | sed 's/:/ /g'`
count=0
for director in $mypath
do
check='ls $director'
for item in $check
do
count=$[ $count + 1 ]
done
echo $director - $count
count=0
done
~
以上是统计$PATH目录下文件的个数,以下是执行结果
[root@rac1 ~]# ./test3
/usr/kerberos/sbin - 2
/usr/kerberos/bin - 2
/usr/local/sbin - 2
/usr/local/bin - 2
/sbin - 2
/bin - 2
/usr/sbin - 2
/usr/bin - 2
/usr/X11R6/bin - 2
/root/bin - 2
我哪里错了么?
|
把第六行的
'ls $director'
改成
`ls $director`
'ls $director'
改成
`ls $director`