Subject: Re: bug#11991: tr bug

From: Eric Blake <[email-masked]>
Date: Thu, 19 Jul 2012 10:44:15 -0600

tag 11991 notabug
thanks

[Your message was encoded in Chinese; these days, you are more likely to
achieve interoperability if you encode in UTF-8 instead]

On 07/19/2012 12:38 AM, Xiao, Bellon (NSN - CN/Cheng Du) wrote:
> Hi,
> 
> We found a bug of tr, the version is tr (coreutils) 5.2.1

That's extremely old.  Have you considered updating?  The latest stable
version is 8.17, and there have been fixes to tr in the meantime (but
not for your particular issue).

> Here is the symptom:
> When there is a file named e or r under current directory, tr will take effect，like：
> 	echo hello |tr [a-z] [A-Z] 
> 	echo hello |tr [:lower:] [:upper:]

You are missing shell quoting.

> will return hello
> 
> And when is a file named l, o, p, u or w under current directory, tr will give error message like:
> 	echo hello |tr [a-z] [A-Z] 
> 	echo hello |tr [:lower:] [:upper:]
> gives : tr: misaligned [:upper:] and/or [:lower:] construct

Try the following to see the difference shell quoting makes:

echo tr [a-z] [A-Z]
echo tr '[a-z]' '[A-Z]'

The shell is expanding your glob before 'tr' ever sees the command line,
because you happened to have files that matched the glob; in turn, that
means you weren't executing the tr arguments that you thought you were.
 The quoting is necessary to avoid shell globbing from interfering.

I'm therefore closing this as not a bug in coreutils, but in your usage
pattern.

-- 
Eric Blake   [email-masked]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org