views:

39

answers:

2

I am exporting a portion of a local prototypte svn repository to import into a different repo. We have a number of svn properties set throughout the repo so I figured I would write a script to list the file elements and their corresponding properties. How hard can that be right.

So I write started writing a bash script that would assign the output of the svn proplist -v to a variable so I could check if the specified file had any properties.

#!/bin/bash
o=$(svn proplist -v "$1")
echo $o

now this works fine and echos the output of the svn proplist command. But if the proplist command returns something like

svn:ignore : * build

it performs a shell expansion on the * and inserts the entire directory listing prior to the build property value. So if the directory had a.txt, b.txt and build files/dirs in it, the output would look like.

svn:ignore : a.txt b.txt build

I figure I need to somehow escape the output or something to keep the expansion from happening, but have yet to find something that works. There are other ways to do this, but I hate when I cannot figure something out. and I have to admin, I think this one beat me ( well given the time I can spend on it )

+2  A: 
echo "$o"

will prevent the value from being expanded.

Adam Crume
Wow, I guess I could not see the forest through the trees. I assumed the expansion was taking place in actual assignment rather than the echo. Thanks!
Rob Goodwin
+1  A: 

Although it does perform shell expansion, it's performed at the echo. To see this, issue a set -x within your bash script. Here's an example:

#!/bin/sh
set -x
o=$(echo 'one two *')
echo $o

And here's the output you should see:

++ echo 'one two *'
+ o='one two *'
+ echo one two others from expansion

And if you quote the $o, everything works correctly:

++ echo 'one two *'
+ o='one two *'
+ echo 'one two *'
one two *

You might also try set -v.

Kaleb Pederson