我正在运行一个吐出 IP 的命令,我需要将其提供给位于特定位置的另一个程序,我该怎么做?
$ command1 | command2 -c configfile -i "$1" status
Run Code Online (Sandbox Code Playgroud)
“$1”是我想要 command1 结果所在的位置。
谢谢。
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)