coreutils
[Top][All Lists]
Advanced

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

Re: tr depends on current directory?!


From: Pádraig Brady
Subject: Re: tr depends on current directory?!
Date: Tue, 30 Dec 2014 12:47:05 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 30/12/14 09:40, Kelly Dean wrote:
> root@helpme:/# uname -a
> Linux helpme 3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 i686 GNU/Linux
> root@helpme:/# echo foo | tr [a-z] [A-Z]
> foo
> root@helpme:/# cd usr
> root@helpme:/usr# echo foo | tr [a-z] [A-Z]
> FOO
> root@helpme:/usr# cd ../home/
> root@helpme:/home# echo foo | tr [a-z] [A-Z]
> FOO
> root@helpme:/home# cd ../root/
> root@helpme:~# echo foo | tr [a-z] [A-Z]
> foo
> root@helpme:~# dash
> # pwd
> /root
> # echo foo | tr [a-z] [A-Z]
> foo
> # cd ../usr
> # echo foo | tr [a-z] [A-Z]
> FOO
> # tr --version
> tr (GNU coreutils) 8.13
> ...
> 
> Somebody, please tell me I'm not drooling on myself in a straightjacket in a 
> padded room.
> 
> Oh, I just discovered that the coreutils manual (even though not the tr man 
> page) says gnu tr doesn't support brackets for ranges, which only ‟sometimes” 
> work. But seriously, it's supposed to depend on the current directory?

[] is significant to the shell and will expand
to a single letter file name if present in the directory.
You need to quote like:

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

Note the brackets are redundant for POSIX ranges,
but are more portable to specify as solaris tr requires them for example.

Another portability gotcha is that tr '[a-z]' '[A-Z]'
is only portable to solaris the XPG4 implementation in the C locale.
I.E. needs to be LC_ALL=C tr '[a-z]' '[A-Z]'.

Another gotcha is that specifying ranges like this
doesn't cater for non ASCII letters like á etc.
In that case character classes are better:

  tr '[:lower:]' '[:upper:]'

cheers,
Pádraig.




reply via email to

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