算上在bash可执行文件的数量 [英] Count the number of executable files in bash
本文介绍了算上在bash可执行文件的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看到了很多关于这个问题的答案,但我并不想这样做,使用找到
。我写了这个东西,但不工作:
I have seen a lot of answers about this subject but I don't want to do this using
find
. I have written this but something not working:
function CountEx()
{
count=0
for file in `ls $1`
do
echo "file is $file"
if [ -x $file ]
then
count=`expr $count + 1`
fi
done
echo "The number of executable files in this dir is: $count"
}
while getopts x:d:c:h opt
do
case $opt in
x)CountEx $OPTARG;;
d)CountDir $OPTARG;;
c)Comp $OPTARG;;
h)help;;
*)echo "Please Use The -h Option to see help"
break;;
esac
done
我使用这个脚本如下所示:
I am using this script like the following:
yaser.sh -x './..../...../.....'
外壳运行它,然后它输出:在这个目录可执行文件的数量是:0
当有此目录中的许多可执行文件。
The shell runs it and then it outputs:
The number of executable files in this dir is: 0
when there is many executable files in this directory.
推荐答案
要算可执行文件的数量(如标题所说)
To count the number of executable (like the title says)
count=0
for file in yourdir/*; do
if [ -x $file ]; then
count=$((count+1));
fi;
done;
echo "total ${count}"
要算的文件夹,只需更改与 -d
To count folders, just change the -x
test with -d
这篇关于算上在bash可执行文件的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文