我想编写一个脚本来计算变量PATH中每个文件夹中的可执行文件数。我的代码:
#!/bin/bash
IFS=":"
for directory in $PATH; do
files=0
ls -l $directory | while read rights x name group siz m d h name; do
if [ `echo $rights | cut -c1` = "-" ]; then
files=$((${files}+1))
fi
done
echo "Directory ${directory} contains ${files} executable files"
done
我想在while循环结束之后和next循环开始之前处理echo,但它总是打印出文件数= 0. if条件内的计数有效。