【问题标题】:Piping the output of a command line tool to a script as a command line argument将命令行工具的输出作为命令行参数传送到脚本
【发布时间】:2011-12-16 06:59:20
【问题描述】:

我想将我的 IP 地址和特定文件传递给使用 xargs 的程序。例如,我希望能够做到的是:

echo "(output of hostname -i) file.txt" | xargs myscript.rb

最好的方法是什么?谢谢!

【问题讨论】:

    标签: shell unix command-line pipe


    【解决方案1】:

    试试这个

    myscript.rb `hostname -i` file.txt
    

    【讨论】:

      【解决方案2】:

      如果你真的需要使用 xargs,你可以在你的回显字符串中使用反引号来指示 shell 它应该运行主机名命令:

      echo "`hostname -i` file.txt" | xargs myscript.rb
      

      否则,cppcoder 的答案就是要走的路。

      【讨论】:

        猜你喜欢
        • 2012-07-19
        • 2022-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-18
        • 1970-01-01
        相关资源
        最近更新 更多