problems getting a segment from a string output

Hi
I'm creating a script that creates files from svn checkout and compress them using tar.gz

the script gets the repository name from command line argument

i need to capture a number from the last line of the output and create a file name from it.

the svn returns output of all the file names from the repository and in the end it says:
revision number xxxxx

i need to get this number and then rename the tar.gz to it

how do i save the output to a variable and get this number

this is the script:

#!/bin/bash
svn co svn://192.168.1.241/$1 temp && tar czf backup.tar.gz temp

thanks

You can capture the revision number with:

variable=$(svn <options> | awk 'END{print $3}')

thanks for your help!
i just need to know now how to keep running the tar command after the svn checkout , otherwise it start working without waiting for the svn checkout to work.

You could try :

revnr=$(svn co svn://192.168.1.241/$1 temp |sed -n 's/Checked out.* //p')&& [ "$revnr" != "" ] && tar czvf /tmp/test.${revnr}tar.gz --exclude=.svn temp

I added --exclude=.svn
You can leave out this option if you want to include the subversion information....

that's look like it would solve this case :b:

i don't really understand everything in that script. i need to learn more.

You got some good documents with examples that i can improve my knowledge ?

Hi tvio, you're welcome..

A little explanation:

revnr=$(svn co svn://192.168.1.241/$1 temp |sed -n 's/Checked out.* //p')

This is the same a what Franklin52 suggested, just the technique of extraction the version string is different. The result is put in the variable revnr. The return code is the return code of the assignment and not that of the checkout so it is always 0. So in fact the first && is bogus and a "; " could also have been used instead. Since we do not have a return of the checkout we need to test the result:

[ "$revnr" != "" ]

If the variable is non-empty then the checkout was successful so we can go ahead with the tar.

As to your question about the information, IMO an O'Reilly book on your favorite shell (hint: pick ksh, pick ksh...) is usually a good place to start, but I am sure there are plenty of online resources...