I have an SVN repository. I have a shell/bash script that's designed to automatically add all unversioned files to the repository. It looks like this:
svn status | grep '^?' | sed 's/^.* /svn add /' | bash;
Which works perfectly, except for when one of my new files has whitespace in the filename. How can I modify this command to deal with that?
To avoid quoting issues here, you should avoid the shell call altogether and use xargs instead, which will also speed up the process:
svn status | grep '^?' | sed -e 's/^? *//' | xargs --no-run-if-empty -d '\n' svn add
This will handle most special characters, but not work to escape newlines, but since these are the record separator for svn status and grep, you won't get much better than that anyway.
Strange that you use a script because svn add --force . can do this alone:
> svn status
? INSTALL
? trunk/INSTALL
? trunk/INSTALL WITH SPACE
> svn add --force .
A trunk/INSTALL
A INSTALL
A trunk/INSTALL WITH SPACE
No more fuss with whitespace :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With