【问题标题】:What is the syntax for xargs' -I flag argument? [closed]xargs 的 -I 标志参数的语法是什么? [关闭]
【发布时间】:2021-09-06 07:56:38
【问题描述】:

文档只用文字模糊地说明了它的作用,我在互联网上找不到任何示例。

那么,我该如何使用 xargs 的 -I 标志呢?我知道它与参数命令中的字符串替换有关,但不清楚如何使用它。

【问题讨论】:

    标签: linux shell xargs


    【解决方案1】:

    来自tldr xargs:

    - Execute the command once for each input line, replacing any occurrences of the placeholder (here marked as `_`) with the input line:
    
        arguments_source | xargs -I _ command _ optional_extra_arguments
    

    所以,是这样的:

    $ echo "foo" | xargs -I _ echo "bar-"_
    bar-foo
    

    xargs 接受输入 foo,用它替换 _,而不是打印 bar-_ 打印 bar-foo 到控制台

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 2023-03-15
      相关资源
      最近更新 更多