【发布时间】:2021-09-06 07:56:38
【问题描述】:
文档只用文字模糊地说明了它的作用,我在互联网上找不到任何示例。
那么,我该如何使用 xargs 的 -I 标志呢?我知道它与参数命令中的字符串替换有关,但不清楚如何使用它。
【问题讨论】:
文档只用文字模糊地说明了它的作用,我在互联网上找不到任何示例。
那么,我该如何使用 xargs 的 -I 标志呢?我知道它与参数命令中的字符串替换有关,但不清楚如何使用它。
【问题讨论】:
来自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 到控制台
【讨论】: