像是GNU xargs的bug
xargs.c的read_line函数里:
893 /* POSIX: In the POSIX locale, the separators are <SPC> and
894 * <TAB>, but not <FF> or <VT>.
895 */
896 if (!bc_ctl.replace_pat && ISBLANK (c))
897 {
898 *p++ = '\0';
899 len = p - linebuf;
900 if (EOF_STR (linebuf))
901 {
902 eof = true;
903 return first ? -1 : len;
904 }
905 bc_push_arg (&bc_ctl, &bc_state,
906 linebuf, len,
907 NULL, 0,
908 initial_args);
909 p = linebuf;
910 state = SPACE;
911 first = false;
912 continue;
913 }
这一段状态机代码应该是“之前读到了普通字符,这次读到了空格”的处理,这时候应该把已经读到的这一段作为一个参数加到列表里去
看它的判断条件if (!bc_ctl.replace_pat && ISBLANK (c))
其实是要求没用-i/-I参数,且本次读到的字符为空白
验证一下:
echo a b c d e |xargs -n1 -i{} echo begin {} end
命令的结果是原帖说的错误
begin a b c d e end
但是去掉-i之后
echo a b c d e |xargs -n1 echo begin {} end
运行结果就几乎正确了。虽然丧失了使用占位符的能力,但至少它确实按照空格进行分割了
begin {} end a
begin {} end b
begin {} end c
begin {} end d
begin {} end e
我觉得这个判断条件就是个bug
【 在 JulyClyde 的大作中提到: 】
: 比较奇怪的是,GNU xargs的manpage写的是:
: This manual page documents the GNU version of xargs. xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines
: 按说应该支持空格啊
: ...................
--
FROM 222.71.112.*