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

Vic*_*tor 2 bash

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

$ command1 | command2  -c configfile -i "$1" status
Run Code Online (Sandbox Code Playgroud)

“$1”是我想要 command1 结果所在的位置。

谢谢。

kar*_*kfa 5

xargs是你的工具

$ command1 | xargs -I {} command2 -c configfile -i {} status
Run Code Online (Sandbox Code Playgroud)

您可以多次引用该参数,例如

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

this, this, and this
Run Code Online (Sandbox Code Playgroud)

根据最后的评论,也许你想做这样的事情

$ var=$(command1) && command2 "$var" ... | command3 "$var" ...
Run Code Online (Sandbox Code Playgroud)