views:

75

answers:

2

I am writing a shell script (which I suck at) and I need some help. Its a script that is moving things from git to CVS (not important). The thing is, i a file path:

controllers/listbuilder/setup/SubmissionRolesListbuilderHandler.inc.php

and I need to be able to do:

cvs add controllers;
cvs add controllers/listbuilder;
cvs add controllers/listbuilder/setup;
cvs add controllers/listbuilder/setup/SubmissionRolesListbuilderHandler.inc.php

Can someone help me out? The best I've come up with so far is to recursively add ALL files in my working tree, but that seems overly inefficient.

EDIT: I was asked for clarification. Here goes: I want to be able to CVS ADD files, given a list of file paths, and somehow handle the addition of new folders when necessary.

+1  A: 

Add all directories:

find . -type d -exec cvs add {} \;

Add all files:

find . -type f -exec cvs add {} \;

I'm not sure what you really want to achieve.

Nikolai Ruhe
no. you'll see i already discovered that solution. I want something that will only do the cvs add on the directory related to my changed file. My working tree is very large and doing this would be inefficient.
pocketfullofcheese
You should more clearly describe what you want to achieve.
Nikolai Ruhe
A: 

This is somewhat kluge-ish, and will no doubt fail if you give it a dirty look, but:

mkdir a/b/c/d

remain="a/b/c/d/"
while echo "$remain" | grep -q / ; do
    dir="$(echo "$remain" | cut -d/ -f1)"
    remain="$(echo "$remain" | cut -d/ -f2-)"

    echo "Do something with dir $dir"
done

This script is more of an idea than a complete solution. For example, if you need the full relative path (not just dir name), you could count up to the number of slashes, using cut -d/ -f1-$i.

derobert