Leading on from this question, I'm trying to write a bash script which will recurse two directories from the directory containing my subversion repositories, checking whether directories are repositories. There will be a mix of directories and repositories, and some repos hiding in those sub-dirs.

Any Subversion repos discovered should have their name printed to an output file, followed by the output of svnadmin verify.

I have the following snippet to check whether a directory is a repository:

svnlook info /path/to/repo >/dev/null

So I'm throwing away the svnlook output, a return code of 0 indicates that it is indeed a SVN repo. I could use this snippet, in an if statement to run svnadmin verify if 0 is returned.

I've tried:

find /dir/containing/repos -maxdepth 2 -type d -exec bash -c 'if [ "svnlook info {} >/dev/null" = 0 ] ;then ;echo "{}" >>output.txt ;svnadmin verify "{}" >>output.txt ;fi' \;

Though I get the following warning for each directory found:

bash: -c: -line 0: syntax error near unexpected token ';'

I think I'm trying to unnecessarily cram it all into one find command, which I'm getting wrong anyway. What would be the best way to structure this task?


You don't need ; after then in then ;echo "{}" >>output.txt.

Use :

then echo "{}" >>output.txt

Also note that rather than playing with {} use positional parameters of shell (i am not familiar with svn so relying upon your commands) :

find /dir/containing/repos -maxdepth 2 -type d -exec bash -c 'if svnlook info /path/to/repo >/dev/null ;then echo "$1" >>output.txt ;svnadmin verify "$1" >>output.txt ;fi' _ {} \;
  • if svnlook info /path/to/repo >/dev/null will run the command and redirect the STDOUT to /dev/null

  • If the svnlook info /path/to/repo command is successful (exit code 0), then echo "$1" >>output.txt ;svnadmin verify "$1" >>output.txt commands will be run

  • Here we are using the directory names {} as the fist argument ($1) to be processed by shell.

  • _ here is just a placeholder indicating positional parameter 0 as bash -c command starts considering any further argument after the command starting from 0. As _ is the zero-th argument, we can use {} as the first argument. Check man bash to get more idea.

  • Thanks again, it turns out that I also needed a & in svnadmin verify "$1" &>>output.txt to get what I wanted from the command, and used "$1" to replace the /path/to/repo part for svnlook. What does the _ do near the end of line? – Arronical Jul 23 '15 at 10:57
  • @Arronical Glad i could help..check my edits.. – heemayl Jul 23 '15 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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