加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 将多行STDIN输入提供给命令

发布时间:2020-12-15 18:28:48 所属栏目:安全 来源:网络整理
导读:我有一个输出git repository SSH URL的脚本,如下所示: git@example.com:namespace/project.gitgit@example.com:another_namespace/some_other_project.git 我想为每一行运行命令git clone(或其他命令). 我尝试将它连接到xargs,但我要么输出一行,要么多行输
我有一个输出git repository SSH URL的脚本,如下所示:
git@example.com:namespace/project.git
git@example.com:another_namespace/some_other_project.git

我想为每一行运行命令git clone(或其他命令).

我尝试将它连接到xargs,但我要么输出一行,要么多行输入转储到单个命令.

如何通过管道在每一行上运行任意命令?

事实证明,你可以在bash中使用while循环(改编自 this answer):
<whatever your command/output is> | while read line; do echo $line; done

其中echo是您的命令,并使用$line作为每行的输出,您可以根据需要进行调整.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读