- 主题:GNU和BSD版本的xargs 分隔符不同
这个看看?
https://unix.stackexchange.com/questions/428310/problem-using-xargs-max-args-replace-with-default-delimiter
{quote}
That behaviour (that newline should be the only delimiter with -I) is
documented in the GNU xargs documentation and the POSIX specification (under
XSI, so it's not surprising that OpenBSD doesn't comply there). In any case,
using -n with -I makes little sense as {} is to replace one argument anyway.
{quote}
$ printf "%s\n" a b c d e | xargs -I{} echo begin {} end
begin a end
begin b end
begin c end
begin d end
begin e end
【 在 JulyClyde 的大作中提到: 】
: 例子:
: list="a b c d e"; echo $list |xargs -n1 -I{} echo begin {} end
: 在Mac上执行结果:
: ...................
--
修改:haha103 FROM 182.150.115.*
FROM 182.150.115.*
我不是说非要用printf来怎么样,我是说这个link里面说GNU xargs/POSIX的文档说明了这个问题。。。(是一个已知问题,甚至是一个feature,不是问题)
-I replstr
[XSI] [Option Start] Insert mode: utility is executed for each logical line
from standard input. Arguments in the standard input shall be separated only
by unescaped <newline> characters, not by <blank> characters. Any unquoted
unescaped <blank> characters at the beginning of each line shall be ignored.
The resulting argument shall be inserted in arguments in place of each
occurrence of replstr. At least five arguments in arguments can each contain
one or more instances of replstr. Each of these constructed arguments cannot
grow larger than an implementation-defined limit greater than or equal to 255
bytes. Option -x shall be forced on. [Option End]
【 在 JulyClyde 的大作中提到: 】
: xargs的stdin不太好控制
: 我这里其实是echo了一个array出来,就是用空格的
: 改printf不太方便吧
: ...................
--
修改:haha103 FROM 182.150.115.*
FROM 182.150.115.*
所以只有其他程序来迁就它了,毕竟标准就这么规定的 :)
【 在 JulyClyde 的大作中提到: 】
: 标 题: Re: GNU和BSD版本的xargs 分隔符不同
: 发信站: 水木社区 (Fri Jan 13 14:37:02 2023), 站内
:
: 按这个文档的话,GNU的倒是符合标准
: 但是不满足需求啊
:
: 我原来想的是-I强制-n1(因为一个占位符只能替换成一个参数),但是不应该影响参数
: 解析的过程
: 没想到它居然强制使用“一整行”来作为一个参数
: 【 在 haha103 的大作中提到: 】
: : 我不是说非要用printf来怎么样,我是说这个link里面说GNU xargs/POSIX的文档说明
: : 了这个问题。。。(是一个已知问题,甚至是一个feature,不是问题)
: : -I replstr
: : [XSI] [Option Start] Insert mode: utility is executed for each logical line
: : ...................
:
: --
:
: ※ 来源:·水木社区 mysmth.net·[FROM: 222.71.112.*]
--
FROM 182.150.115.*