gpt4 book ai didi

bash - 使用单行命令获取所有分支的 SVN url

转载 作者:行者123 更新时间:2023-11-29 09:29:32 25 4
gpt4 key购买 nike

我正在尝试检索存储库中所有分支的 svn url。我使用一个简单的 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 的输出接受 Word-Splitting由 shell 完成。

引用自 xargsman 页面,

-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.

关于bash - 使用单行命令获取所有分支的 SVN url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com