日期:2014-05-16  浏览次数:20646 次

linux shell 脚本
#!/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


我哪里错了么?
linux?shell

------解决方案--------------------
把第六行的
'ls $director'
改成
`ls $director`