views:

295

answers:

5

I want to write a shell script in bash to deploy websites from an svn repository. When I deploy a website, I name the exported directory *website_name*-R*revision_number*. I'd like the bash script to automatically rename the exported directory, so it needs to learn the current revision number from the export directory. If I run

$> svn info http://svn-repository/trunk

Path: trunk
URL: http://svn-repository/mystery/trunk
Repository Root: http://svn-repository/mystery
Repository UUID: b809e6ab-5153-0410-a985-ac99030dffe6
Revision: 624
Node Kind: directory
Last Changed Author: author
Last Changed Rev: 624
Last Changed Date: 2010-02-19 15:48:16 -0500 (Fri, 19 Feb 2010)

The number after the string Revision: is what I want. How do I get that into a bash variable? Do I do string parsing of the output from the svn info command?

+3  A: 
REVISION=`svn info http://svn-repository/trunk |grep '^Revision:' | sed -e 's/^Revision: //'`

It's simple, if inelegant.

Paul Tomblin
More succinctly put as:REVISION=`svn info http://svn-repository/trunk | sed -ne 's/^Revision: //p'`
Nathan Kidd
Yeah, I always forget about the -n option to sed.
Paul Tomblin
try using $(..) instead.
ghostdog74
This is useful for more than just the revision number; I just used it to grab the repository URL.
Andres Jaan Tack
+1  A: 

Use svnversion. This will output the revision number/range with minimal additional cruft

oefe
A: 
svn info http://svn-repository/trunk | grep Revision | tr -d 'Revison: '

Spits out the revision Use backticks in your shell script to execute this and assign the results to a variable:

REVISION=`svn info http://svn-repository/trunk | grep Revision | tr -d 'Revison: '`
meagar
A: 

There are probably a dozen different ways to do this, but I'd go with something simple like:

revision="$(svn info http://svn-repository/trunk | grep "^Revision:" | cut -c 11-)"
swestrup
+1  A: 

just use one awk command. much simpler as well.

var=$(svn info http://svn-repository/trunk | awk '/^Revision:/{print $2}')
ghostdog74