bug-coreutils
[Top][All Lists]
Advanced

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

bug#29421: bug in command "tr"


From: wangjian
Subject: bug#29421: bug in command "tr"
Date: Fri, 24 Nov 2017 13:46:24 +0800

Thanks for your quick response! That was really fantastic and impressive!



> On 24 Nov 2017, at 10:34 am, Assaf Gordon <address@hidden> wrote:
> 
> tag 29421 notabug
> close 29421
> stop
> 
> Hello,
> 
> On Thu, Nov 23, 2017 at 6:01 PM, wangjian <address@hidden> wrote:
>> Hi there, I think this is a bug
>> 
>> mkdir empty_foler
>> cd empty_foler
>> touch a
>> echo "abc" | tr [:blank:] +  # you will get “+bc” as output, instead of “abc”
>> touch b
>> echo "abc" | tr [:blank:]  # you will get “bbc” as output, instead of “abc”
> 
> This is not a bug, simply incorrect usage of the parameters on the shell.
> Your shell (e.g. bash) expands unquoted [:blank:] to match ANY
> file with names matching a/b/l/n/k , and replaces them on the commandline
> BEFORE executing 'tr'.
> Only if no files match a/b/l/n/k, then the string '[:blank:]' is
> passed on to tr as-is.
> 
> Observe the following (in an empty directory):
> 
> $ echo [:blank:]
> [:blank:]
> 
> $ touch a
> $ echo [:blank:]
> a
> 
> $ touch b
> $ echo [:blank:]
> a b
> 
> As opposed to using quotes:
> 
> $ echo "[:blank:]"
> [:blank:]
> 
> 
> And so, once you created the files a and b,
> the command you executed was equivalent to
>    echo abc | tr a b
> which indeed results in "bbc".
> 
> To avoid such issues, always quote the parameters to 'tr'.
> 
> regards,
> - assaf






reply via email to

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