Tue 20 Aug 2013 06:08:45 PM UTC, comment #3:
I agree that the proposed paragraph is not adequate, and have written more extensive revisions to the xargs man page, to be submitted immediately.
I will not be using |tr \\n \\0|xargs -0 anymore because |xargs -d\\n takes fewer keystrokes. I wasn't aware of that option until I started working on a revision to the man page.
In reply to
Solving the problem for whitespace-but-not-newlines only solves part of the problem. Examples in manpages should, as far as possible, not come with pitfalls.
It is very easy to create filenames containing blanks, tabs, quote marks, or backslashes using desktop GUI applications. Those applications refuse to create filenames containing newlines. Thus, failure to handle newlines is not so much of a pitfall for desktop users.
Since there are many useful tools for massaging file names that lack --null options (such as grep and sed), and since GUI users (who will be reading the man page to learn to use xargs) still need to use shell commands to deal with many filenames at once, none of which contain newlines, the manpage should not begin by suggesting that the default options are useful.
Lack of a -0 option isn't a problem in the case you suggest (since the program being invoked, xargs, has -0).
(Actually, the program is ls | grep). Now grep does have a
-Z option, but that is for the case when grep is reporting a list of files which contain an instance of the pattern. It would be nice if grep had an option to treat newlines like other whitespace and nulls like newlines, but it doesn't.
Well, ok, if I know that filenames do not contain \01 characters, I can write find ... -print0 | tr \\n\\0 \\1\\n | grep ... | tr \\1\\n \\n\\0 | xargs -0, but this is a lot of keystrokes when I happen to know the filenames do not contain newlines.
find . -maxdepth 1 -mindepth 1 -regex regexp -exec stat {} \+
requires more keystrokes and new users have no chance of coming up with it from memory. Efficiency is just not a problem on modern single-user systems.
|