summaryrefslogtreecommitdiffstats
path: root/recurse_apply
blob: 3e7c4e6006f3737d27b188b02ccb9f6d92327de4 (plain)
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
26
27
28
29
30
31
32
33
#! /bin/sh

R=${R:-"0"}         # recurse
X=${X:-"0"}         # apply CMD on executable files
V=${V:-"0"}         # verbose mode
CMD=${CMD:-"file"}
recurse_apply() {
    #echo $@ $V $R $X $CMD
    for I in $@; do
        if test ! -r $I || test ! -w $I ; then
            if test $V -eq 1; then echo  "->passing $I (not rw)"; fi
        else
            if test -d $I && test $R -eq 1 ; then
                recurse_apply ${I%/}/*
            elif test -f $I ; then
                if test -x $I; then
                    if test $X -eq 1; then
                        if test $V -eq 1; then echo " $CMD $I"; fi
                        $CMD $I || echo "**** error while executing $CMD $I"
                    else #if test $V -eq 1; then
                        echo "$I is executable, use -x to force.";
                    fi
                else
                    if test $V -eq 1; then echo " $CMD $I"; fi
                    $CMD $I || echo "**** error while executing $CMD $I"
                fi
            elif test $V -eq 1; then
                echo  "->passing $I (not a directory or not file)"
            fi
        fi
    done
}
recurse_apply $@