[prev in list] [next in list] [prev in thread] [next in thread] 

List:       coreutils
Subject:    Re: tr depends on current directory?!
From:       Pádraig Brady <P () draigBrady ! com>
Date:       2014-12-30 12:47:05
Message-ID: 54A29EC9.9060505 () draigBrady ! com
[Download RAW message or body]

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.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic