dircount=0
nondir=0
-if [[ $1 == -h ]] ; then #
+if [[ $1 =~ ^--?h(elp)?$ ]] ; then
cat<<EOF
Usage: $0 dirs
Counts how many shell scripts there are in the given directories, how
exit
fi
-for dir in "$@"; do #
+for dir ; do
if [[ -d $dir ]] ; then
- count=$(ls "$dir"/*.sh | wc -l) #
- if (( count > 0 )) ; then #
+ count=$(ls "$dir"/*.sh 2>/dev/null | wc -l)
+ if (( count )) ; then
shdirs+=("$dir")
let filecount+=count
fi
done
-if (( filecount > 0 )) ; then #
+if (( filecount )) ; then
echo Sh-files: $filecount
fi
-if (( ${#shdirs[@]} > 0 )) ; then #
+if (( ${#shdirs[@]} )) ; then
echo Sh-dirs: "${shdirs[@]}"
fi
if (( $# != $nondir )) ; then
echo -n "$filecount/($#-$nondir)="
- echo "$filecount/($#-$nondir)" | bc -l #
+ bc -l <<< "$filecount/($#-$nondir)"
fi