Closed ghost closed 2 years ago
@TwoFinger, that is a nice simplification. Nevertheless, I think that a single tr
command should always be safe. For example, here is what the POSIX man page https://pubs.opengroup.org/onlinepubs/9699919799/nframe.html has to say about tr str1 str2
:
If string2 is present, each input character found in the array specified by string1 shall be replaced by the character in the same relative position in the array specified by string2.
Note the emphasis (mine): it says explicitly that the characters in the input string are replaced; this should exclude characters that result from a substitution already made by tr
itself. Am I perhaps missing something?
@ricandr Indeed, tr
seems to do a single pass through the input stream.
I even tried putting the a-f letters first, numbers second, and it still produced the same result:
% echo 0de345 | tr 0123456789abcdef cbdefghijklnrtuv
ctuefg
% echo 0de345 | tr abcdef0123456789 lnrtuvcbdefghijk
ctuefg
In that case, the NOTE: is unnecessary, too.
Should I add another commit to this PR, or you prefer to make the changes yourself?
Thanks for the feedback. If you want, go ahead and add a new commit to the PR. Bonus (not strictly required): You can even squash the two commits together and force push so that the modified PR still only has a single commit in it.
Thank you, @TwoFinger. I merged the PR.
tr abcdef0123456789 lnrtuvcbdefghijk
worked for GNU tr(1) just as well, but, for another implementation, it might not. Two tr's seem safe enough.