[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a De
From: |
Stephane Chazelas |
Subject: |
[bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed |
Date: |
Wed, 23 Feb 2022 13:03:28 -0500 (EST) |
Follow-up Comment #6, bug #62043 (project findutils):
[comment #4 comment #4:]
[...]
> OTOH I am trying to fix the documentation of xargs' inconsistent behavior,
imho these two commands should produce identical output both for consistency
reasons and according to the documentation but do not:
> printf '\n' | xargs -r echo foo
> printf '\0' | xargs -r -0 echo foo
[...]
(I've added -r to the second which I assume is what you intended)
No they should not, in the first case, the input contains no record, because
without -d/-r, any sequence of unquoted blanks or newlines act as separator
and unquoted leading or trailing blanks or newline are ignored.
Same in
printf '\n\n\t\t \n \n' | xargs -r echo foo
In the second, which is the same as:
printf '\0' | xargs -r -d '\0' echo foo
input is interpreted as NUL delimited records (and there's no quote
processing), so the input contains one such record which happens to be empty.
So echo is called with "foo" and an empty argument. Which on Linux you can see
with:
$ printf '\0' | strace -qqfe execve -e signal='!all' xargs -r -d '\0' echo foo
| sed -n l
execve("/usr/bin/xargs", ["xargs", "-r", "-d", "\\0", "echo", "foo"],
0x7ffdac4335c8 /* 40 vars */) = 0
[pid 1181116] execve("/usr/bin/echo", ["echo", "foo", ""], 0x7ffec72add10 /*
40 vars */) = 0
foo $
In:
printf '' | xargs -d '\0' echo foo
echo is invoked with foo but no extra argument.
printf '\n' | xargs -r -d '\n' echo foo
printf '\0' | xargs -r -0 echo foo
printf ' \n\n "" \t\t\n\n\n' | xargs -r echo foo
Should give the same output and do.
My suggested wording should hopefully clarify things, bearing in mind that how
the input is broken into the records that make up the arguments to be passed
to the command is documented elsewhere.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?62043>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed, Paul Eggert, 2022/02/13
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed, Andreas Metzler, 2022/02/13
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed, Andreas Metzler, 2022/02/13
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed, Stephane Chazelas, 2022/02/23
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed, Andreas Metzler, 2022/02/23
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed, James Youngman, 2022/02/23
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed,
Stephane Chazelas <=
- [bug #62043] The xargs -r, --no-run-if-empty Option Is Ignored When a Delimiter Is Passed, Andreas Metzler, 2022/02/24