aboutsummaryrefslogtreecommitdiff
path: root/bin/cf
blob: 3063d58b60187d8c9808be3a65644bb11c8a061a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# Count entries in a given set of directories
ex=0
for dir in "${@:-.}" ; do

    # Warn if a non-directory was given, flag errors, but continue
    if ! [ -d "$dir" ] ; then
        printf >&2 'cf: %s: not a directory\n' "$dir"
        ex=1
        continue
    fi

    # Add files matching glob, shift them off if unexpanded (first and only
    # entry doesn't exist)
    set -- "$dir"/*
    [ -e "$1" ] || shift

    # Add dot files, shift off the "." and ".." entries
    set -- "$dir"/.* "$@"
    shift 2

    # Print number of parameters
    printf '%u\t%s\n' "$#" "$dir"
done
exit "$ex"