使用单行命令获取所有分支的 SVN url
Getting SVN url of all branches using single line command
我正在尝试检索所有分支的 svn url os a repository 。我使用一个简单的 bash 脚本得到了结果。
我可以使用 "xargs" 做同样的事情吗?我无法控制 xargs 命令。
我试过这样的东西
svn ls https://my.svn.net/svn/projectA/branches | xargs -0 -I {} svn info {}\ ;
这仅打印 svn ls 的结果。
有什么想法吗?
编辑
svn ls 的输出
svn ls https://my.svn.net/svn/projectA/branches
branch1
branch2
branch3
branch4
使用 xargs 时的预期输出
https://my.svn.net/svn/projectA/branches/branch1
https://my.svn.net/svn/projectA/branches/branch2
...
...
你只需从 xargs
中删除 -0
标志,这意味着读取 NULL
去限制输出,只需执行
svn ls https://my.svn.net/svn/projectA/branches | xargs -I {} svn info "{}"
在这里,svn ls ..
的输出通过管道传输到 xargs
并存储在 {}
中,它充当接收值的占位符,然后 svn info
要求每个分支机构提供您想要的信息。注意 {}
周围的双引号,添加是为了防止 svn ls
的输出接受 shell.
完成的 Word-Splitting
引用 xargs
的 man
页,
-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.
从评论来看,好像您想附加 URL
每个分支名称,您可以这样做
svn ls https://my.svn.net/svn/projectA/branches | \
xargs -I {} svn info "https://my.svn.net/svn/projectA/{}"
与当前答案无关。此外,如果您正在使用 GNU xargs
,您可以使用它的 -r
标志来确保命令不是 运行 来自管道的空输入。
xargs -r -I {} svn info "https://my.svn.net/svn/projectA/{}"
一个 man
页面引用,
-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.
我正在尝试检索所有分支的 svn url os a repository 。我使用一个简单的 bash 脚本得到了结果。 我可以使用 "xargs" 做同样的事情吗?我无法控制 xargs 命令。
我试过这样的东西
svn ls https://my.svn.net/svn/projectA/branches | xargs -0 -I {} svn info {}\ ;
这仅打印 svn ls 的结果。
有什么想法吗?
编辑
svn ls 的输出
svn ls https://my.svn.net/svn/projectA/branches
branch1
branch2
branch3
branch4
使用 xargs 时的预期输出
https://my.svn.net/svn/projectA/branches/branch1
https://my.svn.net/svn/projectA/branches/branch2
...
...
你只需从 xargs
中删除 -0
标志,这意味着读取 NULL
去限制输出,只需执行
svn ls https://my.svn.net/svn/projectA/branches | xargs -I {} svn info "{}"
在这里,svn ls ..
的输出通过管道传输到 xargs
并存储在 {}
中,它充当接收值的占位符,然后 svn info
要求每个分支机构提供您想要的信息。注意 {}
周围的双引号,添加是为了防止 svn ls
的输出接受 shell.
引用 xargs
的 man
页,
-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.
从评论来看,好像您想附加 URL
每个分支名称,您可以这样做
svn ls https://my.svn.net/svn/projectA/branches | \
xargs -I {} svn info "https://my.svn.net/svn/projectA/{}"
与当前答案无关。此外,如果您正在使用 GNU xargs
,您可以使用它的 -r
标志来确保命令不是 运行 来自管道的空输入。
xargs -r -I {} svn info "https://my.svn.net/svn/projectA/{}"
一个 man
页面引用,
-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.