-11

My suggested edit was rejected by the OP:

https://stackoverflow.com/review/suggested-edits/28386699

This edit deviates from the original intent of the post. Even edits that must make drastic changes should strive to preserve the goals of the post's owner.

Can someone clarify what exactly "deviates from the original intent"?

Here is an explanation for each change made:

  1. Remove -Z from egrep:
     find /etc/passwd -print0 |
-        xargs -0 egrep -Z 'root|www' |
+        xargs -0 egrep 'root|www' |
         tr "\n" "\0" |
         xargs -0 -n1

Using that flag makes the use of tr here completely redundant at best, and the entire point of this example is to showcase tr. At worst, tr mangles filenames with \n in them, which makes the -Z flag redundant instead.

  1. Specify that GNU tr is not required and explain the limitations of tr:
-## Use `tr` from GNU Coreutils
+## Use `tr`
+
+Unlike `grep -Z`, this alternative [is POSIX][2]/is not GNU-specific, but it will not work properly if a filename contains one or more newline characters.

[...]

   [1]: http://www.gnu.org/software/grep/manual/grep.html#Output-Line-Prefix-Control
+  [2]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tr.html

This seems misleading, as there is virtually nothing in this answer that specifically requires GNU tr is to be used.

Also misleading is the fact that in this answer, there is no indication at all that the result of using tr is any different from grep -Z, when the entire point of using grep -Z (and find -print0 and xargs -0, ...) is to avoid pitfalls such as filenames with newlines embedded in them (which is the problem of using tr). Thus, this change ensures that the reader is at least aware of that.

  1. Ensure the use of a space after xargs -n, for better portability:
-        xargs -0 -n1
+        xargs -0 -n 1

The number is specified as a separate argument on the POSIX xargs manual:

-n number

Invoke utility using as many standard input arguments as possible, up to number (a positive decimal integer) arguments maximum. Fewer arguments shall be used if:

  1. Use the octal notation instead of \0, for better portability:
-        tr "\n" "\0" |
+        tr "\n" "\000" |

From the POSIX tr manual:

The -escape sequences in XBD Escape Sequences and Associated Actions ( '\', '\a', '\b', '\f', '\n', '\r', '\t', '\v' ) shall be supported. The results of using any other character, other than an octal digit, following the are unspecified. Also, if there is no character following the , the results are unspecified.

[...]

Unlike some historical implementations, this definition of the tr utility correctly processes NUL characters in its input stream. NUL characters can be stripped by using:

tr -d '\000'

  1. Change double quotes to single quotes:
-        tr "\n" "\0" |
+        tr '\n' '\0' |

To make it clear that the contents are not special in any way (unlike e.g.: variables and $'\n'). That may be considered to be a matter of personal preference, but would that in and of itself be a reason for rejecting this edit?

1 Answer 1

20

Don't change working code on accepted or notably upvoted answers. This particular answer was written 7 years ago, and (while certainly not perfect) has stood the test of time. If you have comments about edge cases, or want to post an alternative or related answer, please do.

Changing the narrative flow of an answer, introducing stylistic changes to working code, or attempting to generalize a solution that's been designated by the author as implementation- or platform-specific are often rejected by the community because such edits inherently deviate from the author's original intent. This can be especially problematic when you're editing posts without factoring in all the other answers, comments, and (in many cases now-missing) back-and-forth between the question's OP and the community trying to assist them with answers.

There are exceptions to every rule, especially when it comes to fixing obvious syntax errors, readability issues, or obsolete links or flags. This was not one of those cases, and I would have voted to reject the edit for a number of reasons regardless of who the post author was.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .