Pádraig Brady <[email protected]> writes:
> On 05/01/2026 23:04, Daniel Dallos via GNU coreutils General Discussion wrote:
>> A Red Hat bug report was resolved by quoting the regex passed to tr,
>> to keep the shell from interpolating.
>> It is suggested this information to be included in the help message:
>> diff --git a/src/tr.c b/src/tr.c
>> index 8a184f17a..84f1dfc08 100644
>> --- a/src/tr.c
>> +++ b/src/tr.c
>> @@ -344,6 +344,8 @@ ARRAY1 by repeating its last character as
>> necessary. Excess characters\n\
>> of ARRAY2 are ignored. Character classes expand in unspecified order;\n\
>> while translating, [:lower:] and [:upper:] may be used in pairs to\n\
>> specify case conversion. Squeezing occurs after translation or
>> deletion.\n\
>> +Arguments passed to tr should be quoted, so that the shell doesn't\n\
>> +Interpret regex characters intended for tr.\n\
>> "), stdout);
>> emit_ancillary_info (PROGRAM_NAME);
>> }
Not directly related to your issue, but 'tr' doesn't operate on regular
expressions. It isn't super intuitive, but I guess POSIX ran into enough
problems that thought thought it was worth mentioning explicitly [1]:
It should be noted that, despite similarities in appearance, the
string operands used by tr are not regular expressions.
> Well that applies to many utils (any that accept backslash escapes at least).
Agreed. I think it is probably best to leave the explanation of quoting
to the shell's documentation since it affects so much [2].
Collin
[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/tr.html
[2] https://www.gnu.org/software/bash/manual/bash.html#Quoting