1

I want to use a variable in a svn setprop svn:externals command in a shell script.

The path is set as a variable, and works fine:

LOCALPATH="/some/path"
TARGETFOLDER="folder"
svn propset svn:externals 'dir -r100 http://svn.example.com/repos/trunk' $LOCALPATH/$TARGETFOLDER/externals

However, if I try to use a variable for the revision number, it doesn't work:

LOCALPATH="/some/path"
TARGETFOLDER="folder"
REV="100"
PROP="'dir -r$REV http://svn.example.com/repos/trunk'"
echo $PROP
svn propset svn:externals $PROP $LOCALPATH/$TARGETFOLDER/externals

The PROP variable is echoed correctly, but the propset doesn't work. I always get the following error:

svn: Cannot specify revision for setting versioned property 'svn:externals'

Any help would be appreciated.

Tim
  • 6,281
  • 3
  • 39
  • 49
  • Try removing the single quotes around `PROP` value. – Antonio Pérez Nov 03 '11 at 11:23
  • I need to wrap the property in single quotes for the `propset` command to work. If I use `svn:external '$PROP' $LOCALPATH` on the final line, `$PROP` is treated as a string literal. – Tim Nov 03 '11 at 11:35

2 Answers2

3

This is a problem with escaping single quotes in shell. See there explained. Playing around with your case found the following combination working:

....
PROP="dir -r$REV http://.../trunk"
svn propset svn:externals ''"$PROP"'' $LOCALPATH/$TARGETFOLDER/externals
Community
  • 1
  • 1
pmod
  • 10,450
  • 1
  • 37
  • 50
1

I do not find anything wrong with your script. I experience the same issue, though.

If you're blocked by this script, you may consider using an external file to set your property:

LOCALPATH="/some/path"
TARGETFOLDER="folder"
REV="100"
PROP="'dir -r$REV http://svn.example.com/repos/trunk'"
echo $PROP > svn.externals
svn propset svn:externals -F svn.externals
# rm svn.externals

Note: Instead of echoing commands when you debug a shell script you can use the xtrace flag:

sh -x myscript.sh

It will output each executed command prepended with with a +.

Antoine
  • 5,158
  • 1
  • 24
  • 37
  • Thanks. Can I remove the `svn.externals` file after setting the property, or is it referenced by subversion ? – Tim Nov 03 '11 at 12:34
  • Yes. Some people like to check this file into svn as well, but I think you shouldn't, as propget would give you the value back. – Antoine Nov 03 '11 at 12:46