Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top