一个变量var
包含多个参数,每个参数由一个新行分隔。
echo "$var" | xargs -I % echo ABC %
#Results in:
#ABC One
#ABC Two
#ABC Three
Run Code Online (Sandbox Code Playgroud)
但是,当省略-I
和%
字符时,我得到以下信息:
echo "$var" | xargs echo ABC
#Results in:
#ABC One Two Three
Run Code Online (Sandbox Code Playgroud)
我曾经读过 {} 将替代当前参数(就像 find 一样),但这不会发生。我究竟做错了什么?
通常的行为xargs
是将尽可能多的参数粘贴到它运行的任何命令的命令行上,迭代'直到它全部完成。以这种方式使用时,它是解决命令行长度限制问题的方法。
但是,当您指定该-I
选项时,它会针对每个参数单独运行命令,一次一个。我认为这在 Linuxxargs -I
选项的文档中并不完全明显,但这就是它们的意思。
-I replace-str
Replace occurrences of replace-str in the initial-arguments with
names read from standard input. Also, unquoted blanks do not
terminate input items; instead the separator is the newline
character. Implies -x and -L 1.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2414 次 |
最近记录: |