3 # descend - walk down a directory tree and execute a command at each node
7 usage="Usage: $name [-afqrv] command [directory ...]\n
8 \040\040-a\040\040All: descend into directories starting with '.'\n
9 \040\040-f\040\040Force: ignore errors during descent\n
10 \040\040-q\040\040Quiet: don't print directory names\n
11 \040\040-r\040\040Restricted: don't descend into RCS, CVS.adm, SCCS directories\n
12 \040\040-v\040\040Verbose: print command before executing it"
15 while getopts afqrv option; do
19 options=$options" "-$option
23 options=$options" "-$option
28 options=$options" "-$option
32 options=$options" "-$option
37 options=$options" "-$option
40 /usr/5bin/echo $usage 1>&2
45 shift `expr $OPTIND - 1`
47 # Get command to execute
48 if [ $# -lt 1 ] ; then
49 /usr/5bin/echo $usage 1>&2
56 # If no directory specified, use '.'
57 if [ $# -lt 1 ] ; then
61 # For each directory specified
62 for dir in $default_dir "$@" ; do
64 # Spawn sub-shell so we return to starting directory afterward
67 # Execute specified command
68 if [ -z "$quiet" ] ; then
69 echo In directory `hostname`:`pwd`
71 if [ -n "$verbose" ] ; then
74 eval "$command" || if [ -z "$force" ] ; then exit 1; fi
76 # Collect dot file names if necessary
77 if [ -n "$alldirs" ] ; then
83 # For each file in current directory
84 for file in $dotfiles * ; do
87 if [ "$file" = "." -o "$file" = ".." ] ; then
91 # If a directory but not a symbolic link
92 if [ -d "$file" -a ! -h "$file" ] ; then
94 # If not skipping this type of directory
95 if [ \( "$file" != "RCS" -a \
96 "$file" != "SCCS" -a \
98 "$file" != "CVS.adm" \) \
99 -o -z "$restricted" ] ; then
101 # Recursively descend into it
102 $fullname $options "$command" "$file" \
103 || if [ -z "$force" ] ; then exit 1; fi
106 # Else if a directory AND a symbolic link
107 elif [ -d "$file" -a -h "$file" ] ; then
109 if [ -z "$quiet" ] ; then
110 echo In directory `hostname`:`pwd`/$file: symbolic link: skipping
114 ) || if [ -z "$force" ] ; then exit 1; fi