我有一个输出 git 存储库 SSH URL 的脚本,如下所示:
git@example.com:namespace/project.git
git@example.com:another_namespace/some_other_project.git
Run Code Online (Sandbox Code Playgroud)
git clone我想为每一行运行命令(或其他命令)。
我尝试将其通过管道传输到xargs,但我要么在一行中获得输出,要么将多行输入转储到单个命令。
如何通过管道在每一行上运行任意命令?
事实证明,您只需使用whilebash 中的循环即可做到这一点(改编自此答案):
<whatever your command/output is> | while read line; do echo $line; done
Run Code Online (Sandbox Code Playgroud)
echo您的命令在哪里,并用作$line每行的输出,您可以根据需要进行调整。