#! /bin/bash
filecount=0
dircount=0
nondir=0

if [[ $1 == -h ]] ; then                    #
    cat<<EOF
Usage: $0 dirs
Counts how many shell scripts there are in the given directories, how
many directories containing such files there are and what is an
average shell scripts count per directory.
EOF
    exit
fi

for dir in "$@"; do                          #

    if [[ -d $dir ]] ; then
        count=$(ls "$dir"/*.sh | wc -l)      #
        if (( count > 0 )) ; then            #
          shdirs+=("$dir")
          let filecount+=count
        fi

    else
        let nondir++
    fi

done

if (( filecount > 0 )) ; then                #
    echo Sh-files: $filecount
fi

if (( ${#shdirs[@]} > 0 )) ; then             #
    echo Sh-dirs: "${shdirs[@]}"
fi

if (( $# != $nondir )) ; then
    echo -n "$filecount/($#-$nondir)="
    echo "$filecount/($#-$nondir)" | bc -l   #
fi