Skip to content

xargs: empty items are dropped with -0 and -d #889

Open

Description

@SichenLiang

With -0 or -d, uutils xargs drops an empty input item when a delimiter appears at the start of the input or immediately after another delimiter.

$ printf 'a\0\0b\0' | xargs -0 printf '[%s]\n'
[a]
[b]

GNU findutils 4.11.0 passes the empty item to the command:

[a]
[]
[b]

The same problem occurs with explicit delimiters, including:

printf 'a,,b,' | xargs -d, printf '[%s]\n'
printf 'a\n\nb\n' | xargs -d '\n' printf '[%s]\n'

Dropping the item also changes the behavior of options that count arguments. For example, GNU runs test -n '' here and exits 123, while uutils skips that invocation and exits 0:

printf 'a\0\0b\0' | xargs -0 -n1 test -n

Likewise, printf '\0' | xargs -0 -r printf '[%s]\n' prints [] with GNU but runs nothing with uutils.

This is specific to byte-delimited input. Without -0 or -d, empty lines do not become empty arguments.

Tested on Linux x86_64 against GNU findutils 4.11.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions