bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#13295: Possible bug - tr utility


From: Erik Auerswald
Subject: bug#13295: Possible bug - tr utility
Date: Sat, 29 Dec 2012 00:46:51 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.11) Gecko/20121123 Icedove/10.0.11

Hi Randy,

On 12/28/2012 06:37 PM, Killen, Randy wrote:
Hello -

I encountered the situation shown below so thought that I would report it to 
see if it might be a bug or is expected behavior.  Please let me know if you 
need additional information.

Randy


$
$ echo something | tr [:lower:] [:upper:]
SOMETHING
$ echo something | tr '[:lower:]' '[:upper:]'
SOMETHING
$
$ touch l
$ echo something | tr [:lower:] [:upper:]
tr: misaligned [:upper:] and/or [:lower:] construct
$ echo something | tr '[:lower:]' '[:upper:]'
SOMETHING
$ rm l
$
$ touch u
$ echo something | tr [:lower:] [:upper:]
tr: misaligned [:upper:] and/or [:lower:] construct
$ echo something | tr '[:lower:]' '[:upper:]'
SOMETHING
$ rm u
$
$ touch l
$ touch u
$ echo something | tr [:lower:] [:upper:]
something
$ echo something | tr '[:lower:]' '[:upper:]'
SOMETHING
$ rm l
$ rm u

This is expected behavior, caused by lack of quoting that results in the shell (Bash) interpreting [...] as a wildcard pattern for file name globbing (see glob(7)). If the 'nullglob' option of the shell is disabled (use 'shopt nullglob' to display the current setting), a wildcard that matches no files is kept as is. Thus the wildcards [:lower:] and [:upper:] are either replaced by l resp. u if one of those files exist or kept, if no matching file exists.

Quoting the special characters '[' and ']' by using '[:lower:]' resp. '[:upper:]' (including the quotes) inhibits the shell from interpreting them as file globbing wildcards. Therefore, you should always quote character classes that are meant as arguments to a program.

HTH
Erik





reply via email to

[Prev in Thread] Current Thread [Next in Thread]