On Mon, Jan 16, 2017 at 03:33:00PM +0100, Martin Ziemer wrote:
> On Mon, Jan 16, 2017 at 12:19:31PM +0100, Andreas Kusalananda Kähäri
wrote:
> > I've found an issue with xargs.
> >
> > This works as expected:
> >
> >     $ printf 'hello\nworld\n' | xargs -I arg printf '>%s<\n' "arg"
> >     >hello<
> >     >world<
> >
> > However, when I use nul-termination instead:
> >
> >     $ printf 'hello\00world\00' | xargs -0 -I arg printf '>%s<\n' "arg"
> >     >hello world<
> I got curious and looked into this:
> xargs works as described in the manpage: It invokes the command on
> each LINE of input. If yout replace the delimiter in your first
> example by tab or space, it also starts all tokens in one command.
>
> To get the result, which you expected, you have to use the parameter
> "-n 1" additionally.
>

Well, the manual also says, about "-0":

    Change xargs to expect NUL (‘\0’) characters as separators, instead
    of spaces and newlines.

Note the "instead of".


Here's another oddity:

    printf 'hello\00world\00' | xargs -0 -I arg printf '>%s<\n' "arg"
    >hello world<

    printf 'hello\nthere\00world\00' | xargs -0 -I arg printf '>%s<\n' "arg"
    >hello
    there<
    >world<

Why is the nul treated as a delimiter in the second case, but not in the
first?


Regards,
Kusalananda

[demime 1.01d removed an attachment of type application/pgp-signature which had 
a name of signature.asc]

Reply via email to