gpt4 book ai didi

bash - 如何将第一个命令的输出通过管道传递到下一个命令的特定位置?

转载 作者:行者123 更新时间:2023-12-02 17:21:06 26 4
gpt4 key购买 nike

我正在运行一个吐出 IP 的命令,我需要在它出现时将它提供给位于特定位置的另一个程序,我该怎么做?

$ command1 | command2  -c configfile -i "$1" status

“$1”是我希望 command1 的结果去的地方。

谢谢。

最佳答案

xargs 是您的工具

$ command1 | xargs -I {} command2 -c configfile -i {} status

你可以多次引用参数,例如

$ echo this | xargs -I {} echo {}, {}, and {}

this, this, and this

根据上一条评论,也许您想做这样的事情

$ var=$(command1) && command2 "$var" ... | command3 "$var" ...

关于bash - 如何将第一个命令的输出通过管道传递到下一个命令的特定位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42631070/

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