From unknown Sat Jun 21 05:00:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#11991: tr bug Resent-From: "Xiao, Bellon (NSN - CN/Cheng Du)" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 19 Jul 2012 16:16:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 11991 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 11991@debbugs.gnu.org Cc: "Han, Cathy \(NSN - CN/Cheng Du\)" X-Debbugs-Original-To: Received: via spool by submit@debbugs.gnu.org id=B.134271455031784 (code B ref -1); Thu, 19 Jul 2012 16:16:03 +0000 Received: (at submit) by debbugs.gnu.org; 19 Jul 2012 16:15:50 +0000 Received: from localhost ([127.0.0.1]:50910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrtOG-0008Ga-SC for submit@debbugs.gnu.org; Thu, 19 Jul 2012 12:15:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34089) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrkWV-0000HG-H0 for submit@debbugs.gnu.org; Thu, 19 Jul 2012 02:47:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrkQW-0008Qq-Pk for submit@debbugs.gnu.org; Thu, 19 Jul 2012 02:41:33 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, HTML_FONT_FACE_BAD, HTML_MESSAGE, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:59964) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrkQW-0008Qm-Ml for submit@debbugs.gnu.org; Thu, 19 Jul 2012 02:41:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrkQU-0007Jj-Ql for bug-coreutils@gnu.org; Thu, 19 Jul 2012 02:41:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrkQS-0008Pu-Ku for bug-coreutils@gnu.org; Thu, 19 Jul 2012 02:41:29 -0400 Received: from demumfd001.nsn-inter.net ([93.183.12.32]:13174) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrkQS-0008PM-7E for bug-coreutils@gnu.org; Thu, 19 Jul 2012 02:41:28 -0400 Received: from demuprx017.emea.nsn-intra.net ([10.150.129.56]) by demumfd001.nsn-inter.net (8.12.11.20060308/8.12.11) with ESMTP id q6J6fNP6006878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 19 Jul 2012 08:41:24 +0200 Received: from demuexc022.nsn-intra.net (demuexc022.nsn-intra.net [10.150.128.35]) by demuprx017.emea.nsn-intra.net (8.12.11.20060308/8.12.11) with ESMTP id q6J6fNGl001130 for ; Thu, 19 Jul 2012 08:41:23 +0200 Received: from CNBEEXC007.nsn-intra.net ([10.159.192.12]) by demuexc022.nsn-intra.net with Microsoft SMTPSVC(6.0.3790.4675); Thu, 19 Jul 2012 08:41:23 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01CD6579.2B8B8FCC" Date: Thu, 19 Jul 2012 14:38:55 +0800 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: tr bug Thread-Index: Ac1leStVk+tinlOgTTGFS34s0GotGg== From: "Xiao, Bellon (NSN - CN/Cheng Du)" X-OriginalArrivalTime: 19 Jul 2012 06:41:23.0560 (UTC) FILETIME=[83851E80:01CD6579] X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 8137 X-purgate-ID: 151667::1342680085-000055D8-40A5EF71/0-0/0-0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -5.9 (-----) X-Mailman-Approved-At: Thu, 19 Jul 2012 12:15:47 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) This is a multi-part message in MIME format. ------_=_NextPart_001_01CD6579.2B8B8FCC Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Hi, We found a bug of tr, the version is tr (coreutils) 5.2.1 Here is the symptom: When there is a file named e or r under current directory, tr will take = effect=A3=AClike=A3=BA echo hello |tr [a-z] [A-Z]=20 echo hello |tr [:lower:] [:upper:] 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]=20 echo hello |tr [:lower:] [:upper:] gives : tr: misaligned [:upper:] and/or [:lower:] construct But if you try=20 echo kkhh |tr "[a-z]" "[A-Z]"=20 echo kkhh |tr "[:lower:]" "[:upper:]" There will be no error and it takes effect. Brs Bellon Xiao ------_=_NextPart_001_01CD6579.2B8B8FCC Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: quoted-printable tr bug

Hi,

We found a bug = of tr, the version is tr = (coreutils) 5.2.1

Here is the symptom:

When there is a file named e or r under current = directory, tr will take effect=A3=AClike=A3=BA

        echo = hello |tr [a-z] [A-Z]

        echo hello |tr [:lower:] = [:upper:]

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


But if you try

        echo kkhh |tr = "[a-z]" "[A-Z]"

        echo kkhh |tr = "[:lower:]" "[:upper:]"

There will be = no error and it takes effect.

Brs

Bellon = Xiao

------_=_NextPart_001_01CD6579.2B8B8FCC-- From unknown Sat Jun 21 05:00:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#11991: tr bug Resent-From: Bob Proulx Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 19 Jul 2012 16:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11991 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: "Xiao, Bellon (NSN - CN/Cheng Du)" Cc: 11991@debbugs.gnu.org, "Han, Cathy \(NSN - CN/Cheng Du\)" Received: via spool by 11991-submit@debbugs.gnu.org id=B11991.13427163042214 (code B ref 11991); Thu, 19 Jul 2012 16:46:02 +0000 Received: (at 11991) by debbugs.gnu.org; 19 Jul 2012 16:45:04 +0000 Received: from localhost ([127.0.0.1]:51022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrtqY-0000ZJ-BV for submit@debbugs.gnu.org; Thu, 19 Jul 2012 12:45:03 -0400 Received: from joseki.proulx.com ([216.17.153.58]:39635) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrtqV-0000Yh-5O; Thu, 19 Jul 2012 12:45:00 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id C807E2122D; Thu, 19 Jul 2012 10:38:42 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 802D82DC62; Thu, 19 Jul 2012 10:38:42 -0600 (MDT) Date: Thu, 19 Jul 2012 10:38:42 -0600 From: Bob Proulx Message-ID: <20120719163842.GA14362@hysteria.proulx.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Content-Transfer-Encoding: quoted-printable X-Spam-Score: -1.9 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) retitle 11991 shell file globbing confusion tag 11991 + notabug close 11991 thanks Xiao, Bellon (NSN - CN/Cheng Du) wrote: > We found a bug of tr, the version is tr (coreutils) 5.2.1 Thank you for your report. But this is not a bug in tr but simply a misunderstanding of how your command line shell is working. It is a behavior of the shell and doesn't have anything to do with tr. > Here is the symptom: > When there is a file named e or r under current directory, Here you have made the critical description saying that there are files in the current directory. Shell file globbing is matching those files. You need to quote your arguments to prevent this. > tr will take effect=EF=BC=8Clike=EF=BC=9A > echo hello |tr [a-z] [A-Z]=20 > echo hello |tr [:lower:] [:upper:] > will return hello Those command lines are insufficiently quoted and therefore incorrect. > But if you try=20 > echo kkhh |tr "[a-z]" "[A-Z]"=20 > echo kkhh |tr "[:lower:]" "[:upper:]" > There will be no error and it takes effect. And there you see that you are quoting the arguments to prevent the shell from expanding them. Also the collating sequence depends upon your specific locale. The collation sequence of [a-z] in dictionary ordering is really "aAbBcC...xXyYzZ" and not "abc...z". So when you say "[a-z]" you are getting "aAbBcC...xXyYz" without 'Z' and when you say "[A-Z]" you are really getting "AbBcC...xXyYzZ" with 'A'! In the en_US.UTF-8 locale (for example) what would traditionally have been [A-Z] and [a-z] now must be specified as [:upper:] and [:lower:] instead. (And for grep, sed, awk and other tools you would need to put those in a character class [...] so you want two brackets there with [[:lower:]] and [[:upper:]].) Instead of 'tr' try using 'echo' to see what command line you are actually passing to the tr command. $ echo tr [a-z] [A-Z] $ echo tr [:lower:] [:upper:] $ echo tr "[a-z]" "[A-Z]" $ echo tr "[:lower:]" "[:upper:]" By running the above commands in directories containing single characters and you won't see the arguments verbatim to the command unless you quote them. Since this concerns the shell and not tr I am going to go ahead and mark the bug as closed to clear up the accounting. But please feel free to continue discussing the issue. Bob