简体   繁体   中英

Getting SVN url of all branches using single line command

I am trying to retrieve svn url of all branches os a repository . I got the result using a simple bash script . Can I do the same using "xargs" . I've no grip over the xargs command .

I tried something like this

svn ls https://my.svn.net/svn/projectA/branches | xargs -0 -I {} svn info {}\ ; 

This prints the result of svn ls only .

Any Idea ?

EDIT

Out put of svn ls

svn ls https://my.svn.net/svn/projectA/branches

branch1
branch2
branch3
branch4

expected output while using xargs

https://my.svn.net/svn/projectA/branches/branch1
https://my.svn.net/svn/projectA/branches/branch2
...
...

You just drop the -0 flag from xargs which is meant for reading NULL de-limited output, just do

svn ls https://my.svn.net/svn/projectA/branches | xargs -I {} svn info "{}" 

Here, the output from the svn ls .. is pipe-lined to xargs and are stored in {} which acts as a placeholder for the received values, then svn info is called upon each of the branch to provide the information you want. Notice the double quotes around {} , added to prevent your output from svn ls to undergo Word-Splitting done by the shell.

Quoting from the man page of xargs ,

-0, --null

Input items are terminated by a null character instead of by whitespace , and the quotes and backslash are not special (every character is taken literally). Disables the end of file string, which is treated like any other argument. Useful when input items might contain white space, quote marks, or backslashes. The GNU find -print0 option produces input suitable for this mode.

From the comments, it looks like as if you would want to append the URL each of the branch name, you can do it as

svn ls https://my.svn.net/svn/projectA/branches | \
    xargs -I {} svn info "https://my.svn.net/svn/projectA/{}" 

Not relevant to the current answer. Also if you are using GNU xargs you could use its -r flag to ensure the command is not running on a empty input from the pipeline.

xargs -r -I {} svn info "https://my.svn.net/svn/projectA/{}" 

A man page reference,

-r, --no-run-if-empty

If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. This option is a GNU extension .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM