3 # Copyright (C) 1995-2005 The Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # descend - walk down a directory tree and execute a command at each node
19 usage
="Usage: $name [-afqrv] command [directory ...]\n
20 \040\040-a\040\040All: descend into directories starting with '.'\n
21 \040\040-f\040\040Force: ignore errors during descent\n
22 \040\040-q\040\040Quiet: don't print directory names\n
23 \040\040-r\040\040Restricted: don't descend into RCS, CVS.adm, SCCS directories\n
24 \040\040-v\040\040Verbose: print command before executing it"
27 while getopts afqrv option
; do
31 options
=$options" "-$option
35 options
=$options" "-$option
40 options
=$options" "-$option
44 options
=$options" "-$option
49 options
=$options" "-$option
52 /usr
/5bin
/echo $usage 1>&2
57 shift `expr $OPTIND - 1`
59 # Get command to execute
60 if [ $# -lt 1 ] ; then
61 /usr
/5bin
/echo $usage 1>&2
68 # If no directory specified, use '.'
69 if [ $# -lt 1 ] ; then
73 # For each directory specified
74 for dir
in $default_dir "$@" ; do
76 # Spawn sub-shell so we return to starting directory afterward
79 # Execute specified command
80 if [ -z "$quiet" ] ; then
81 echo In directory
`hostname`:`pwd`
83 if [ -n "$verbose" ] ; then
86 eval "$command" ||
if [ -z "$force" ] ; then exit 1; fi
88 # Collect dot file names if necessary
89 if [ -n "$alldirs" ] ; then
95 # For each file in current directory
96 for file in $dotfiles * ; do
99 if [ "$file" = "." -o "$file" = ".." ] ; then
103 # If a directory but not a symbolic link
104 if [ -d "$file" -a ! -h "$file" ] ; then
106 # If not skipping this type of directory
107 if [ \
( "$file" != "RCS" -a \
108 "$file" != "SCCS" -a \
109 "$file" != "CVS" -a \
110 "$file" != "CVS.adm" \
) \
111 -o -z "$restricted" ] ; then
113 # Recursively descend into it
114 $fullname $options "$command" "$file" \
115 ||
if [ -z "$force" ] ; then exit 1; fi
118 # Else if a directory AND a symbolic link
119 elif [ -d "$file" -a -h "$file" ] ; then
121 if [ -z "$quiet" ] ; then
122 echo In directory
`hostname`:`pwd`/$file: symbolic link
: skipping
126 ) ||
if [ -z "$force" ] ; then exit 1; fi