bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter I


From: Andreas Metzler
Subject: Re: The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed
Date: Tue, 11 May 2021 18:38:22 +0200

On 2021-05-11 Kurt von Laven <kurt.von.laven@gmail.com> wrote:
> Hello,

> When the -r, --no-run-if-empty option is combined with the -d, --delimiter
> or -0, --null options, the -r, --no-run-if-empty option does not
> take effect. The manual describes the intended behavior of the -r,
> --no-run-if-empty option: "If the standard input does not contain any
> nonblanks, do not run the command.  Normally, the command is run once even
> if there is no input.  This option is a GNU extension."
[...]

Hello,

it does not totally not work. xargs does not run on *really* empty input
even with --delimiter/--null:
ametzler@argenau:~$ printf '' | xargs -0 --no-run-if-empty echo blah
ametzler@argenau:~$ printf '' | xargs --delimiter X --no-run-if-empty echo blah
ametzler@argenau:~$ printf 'aXa' | xargs --delimiter X --no-run-if-empty -n 1  
echo blah
blah a
blah a

Which is the important case, since it lets xargs -0 work correctly with
commands producing null-delimited lists like find -print0.

The documented behavior would not make sense, if the list separator is
NULL a space character is content, and not "empty". If one wanted to
extend --no-run-if-empty to have consistent behavior it would need not
run if the input is totally empty or only consists of separator
characters.

I do not think it is worth the effort to change the code (and the
documentation) I would rather suggest to only change the documentation
to say that for --delimiter/--null "non-empty" really means not empty.

cu Andreas
-- 
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]