1

This is what I have so far:

for f in 'svn ls repository_dir'; 
do 
svn checkout repository_dir/$f/trunk/dir1/dir2/dir3/dir4/needed_dir 
done

This works great for the projects (100's of them) that have the needed_dir in the correct place. But some projects ($f) have their directory structure a little different. So "needed_dir" might be in a different location.

In the do loop, how can I tell my bash script to:

"Find "needed_dir". If found, check it out."

Or

"Find "needed_file.txt". If found, check it out."

Thank you for any help

EDIT: Sorry, this may be more of a superuser.com question. I actually meant to write it there. But, maybe someone can help me here too!

3 Answers 3

0

You can use find command of linux.

find will recursively search the directory name you give as an argument.
Suppose you have a directory structure like this:

parent
-dir1
--file1
--file2
--file3
-dir2
--file4
--file5
--file6
--dir3

Now you execute the following command:

find parent -name dir*

You will get an output like this:

parent/dir1
parent/dir2
parent/dir2/dir3

For example see the code below:-

#!/bin/sh
parentdir=$1
tofind=$2
for i in `find $parentdir -name $tofind*`;  # * is added for regular expression..do whatever you need here
do
 #check if it is directory
 if [ -d $i ]; then
    # do what you want to do 
    echo $i
 else
    # do something else
    echo $i
 fi
done

This takes to inputs-->

  1. Your svn parent directory
  2. Name of file/directory to be searched


Hope this helps. Let me know if you need further inputs.
Also you can refer this question

0

Without going greatly into detail (as I don't have the time as of now) here is a short example as to which you can work off of.

#!/bin/bash

sudo updatedb
if [ ! -f testfile1.txt ];
then
filelocation=$(locate awesomeo.txt)
head -10 $filelocation
fi

What it does it updates the file database, if the file you are looking for is not in the current directory then it locates the directory of the file and displays the first ten lines of that file.

But in your case you may want to do filelocation=$(locate forloopvariable) or what you are looking for. This of course instead of an if statement would be the else statement to match your needs.

If you have any other questions feel free to ask.

0

This snippet should work, I guess:

for f in $(svn ls repository_dir); 
do 
  find repository_dir/$f -type d -name needed_dir | xargs -r svn checkout 
done

Not the answer you're looking for? Browse other questions tagged or ask your own question.