[SLL] find insanity
Russell Evans
russell-evans at qwest.net
Tue May 31 20:17:05 PDT 2005
On Tue, 31 May 2005 18:35:41 -0400
"Russell Evans" <russell-evans at qwest.net> wrote:
> On Fri, 27 May 2005 23:59:54 -0700 (PDT)
> "Andrew Sweger" <andrew at sweger.net> wrote:
>
> > On Fri, 27 May 2005, Russell Evans wrote:
> >
> > > If by "find me directories that contain a sub-directory named
> > > ".svn", print the directory name" you what "/home/revans/projects"
> > > when /home/revans/projects/.svn is found then
> > >
> > > for i in `find ~/projects -type d -name .svn -prune` ; do
> > > echo ${i%/*}
> > > done
> > >
> > > revans at linux:~> for i in `find ~/projects -type d -name .svn
> > > -prune` ; do echo ${i%/*} ; done
> > > /home/revans/projects/bar/baz
> > > /home/revans/projects
> > >
> > > Is this what you where looking for?
> >
> > Close. I don't want to know about ~/projects/bar/baz because it's
> > under a directory that already contains a .svn directory.
> >
> > I guess another way to describe my search: find all the top level
> > directories that contain a CVS or Subversion tree within them.
>
> Find and grep solution bash script.
> DIR_FOUND=`eval echo $DIR | grep TEST_DIR`
I left out $ on the TEST_DIR variable call.
Needed to add a trailing / to all the grep tests to make sure a partial
match didn't happen.
The following really works, tested and everything. I changed -p to -n
and $PATTERN to $NAME in this version.
Robert Woodcock's sed and egrep solution is pretty cool.
Thank you
Russell
#!/bin/sh
HELP="$0 -d [ directory path to search ] -n [ direstory name to search
for ]"
getopt -o :d:n 1> /dev/null
for ARG in $@ ; do
case "$ARG" in
-d) shift ; DIRECTORY="$1" ; shift ;;
-n) shift ; NAME="$1" ; shift ;;
esac
done
if [ ! $DIRECTORY ] || [ ! $NAME ] ; then
echo "$HELP"
exit 0
fi
for dir in `find $DIRECTORY -type d -name "$NAME" -prune` ; do
DIR=${dir%/*}
#echo DIR=$DIR
if [ "$ALL_DIR" ] ; then
for TEST_DIR in $ALL_DIR ; do
#echo TEST_DIR=$TEST_DIR
DIR_FOUND=`eval echo $DIR | grep $TEST_DIR/`
TEST_DIR_FOUND=`eval echo $TEST_DIR | grep $DIR/`
#echo DIR_FOUND=$DIR_FOUND
#echo TEST_DIR_FOUND=$TEST_DIR_FOUND
if [ ! $DIR_FOUND ] && [ ! $TEST_DIR_FOUND ] ; then
ALL_DIR="$DIR $ALL_DIR"
break
elif [ $TEST_DIR_FOUND ] ; then
ALL_DIR="$DIR"
break
fi
done
else
ALL_DIR="$DIR"
fi
#echo "ALL_DIR=$ALL_DIR"
#echo ""
done
echo $ALL_DIR
exit 0
More information about the linux-list
mailing list