views:

267

answers:

2

Hi, I am writing a shell script to, among other things, determine the last time a branch was made in a subversion repository. The following code works:


        DEV='http://some/svn/server/'
        BRANCH='some/repos/branches/'
        LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r`
        LAST_UPDATE=${LAST_UPDATE:0:10}

But I am not liking the last two lines. How can I combine them together?

NOTE: 

`svn list http://some/svn/server | sort -r`
will return a list of folders such as:
2009-01-12/
2009-01-11/
...
2009-01-01/

I am just trying to remove the trailing slash

+4  A: 

How about:

    LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r | awk -F\/ '{print $1}'`

I've not tested it, and I'm not sure if the quotes inside the back-ticks will cause any problems, but otherwise I can't see why it wouldn't work...

Ben

Ben
i am theman, but you are the man as well. I almost typed that as "-FV" at first then i realized you were escaping the slash. Nice one, thanks!
No worries! I love awk. It nearly always seems to help in situations like this.
Ben
sed and awk are two beasts i have only recently became brave enough to start messing with
`cut -d/ -f1` is a shorter way of doing what awk is doing there. `sed -e 's:/.*::'` would work too, if you want everything before the first slash (as the awk and cut solutions do). `sed -e 's:/$::'` will only trim a trailing slash. Learn your tools! :)
ephemient
A: 

Another, perhaps more robust suggestion, would be to use basename:

LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r | xargs -i basename {}`

The key advantage is that basename knows about path syntax and will produce a canonical representation no matter what oddball file names you throw at it.

Jon Ericson