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);
}
Well that applies to many utils (any that accept backslash escapes at least).
We should probably use quoted '[:lower:]' and '[:upper:]' in the text above at
least.
It is a real gotcha though as it's usually fine, but once there is a file
named with a single char present in the class in $PWD it may show up as an
error,
or silently misbehave.
I half considered special casing `tr : :` to issue a warning
about possibly unquoted arguments, but that wouldn't be general.
I suppose multiple files would trigger different errors, so we might
issue a "possible unquoted error" for any single char passed twice.
Maybe it's worth doing the following:
if single_char_passed_twice()
if lstat(char))
warn("possibly unquoted character class being used");
cheers,
Padraig