GNU bug report logs - #48329
The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed

Previous Next

Package: coreutils;

Reported by: Kurt von Laven <kurt.von.laven <at> gmail.com>

Date: Mon, 10 May 2021 06:50:02 UTC

Severity: normal

Tags: notabug

Merged with 48330

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Kurt von Laven <kurt.von.laven <at> gmail.com>
To: 48329 <at> debbugs.gnu.org
Subject: bug#48329: The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed
Date: Sun, 9 May 2021 23:04:50 -0700
[Message part 1 (text/plain, inline)]
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."

The following command correctly outputs nothing.
xargs --no-run-if-empty -I str echo str <<< ""

The following command incorrectly outputs 1 empty line.
xargs --no-run-if-empty --delimiter="\n" -I str echo str <<< ""

The following command incorrectly outputs 2 empty lines.
xargs --no-run-if-empty --null -I str echo str <<< ""

As a workaround according to this Stack Overflow answer
<https://stackoverflow.com/a/17287097/3866835>, the following commands
output nothing when the input consists only of whitespace.
[[ $input = *[![:space:]]* ]] && xargs --delimiter="\n" -I str echo str <<<
"$input"
[[ $input = *[![:space:]]* ]] || xargs --null -I str echo str <<< "$input"

Be well,
Kurt von Laven
[Message part 2 (text/html, inline)]

This bug report was last modified 3 years and 100 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.