site  contact  subhomenews

'tr' mystery

February 06, 2010 — BarryK
One of the scripts in Woof has suddenly gone crazy. I found the cause: the 'tr' utility has suddenly developed an abnormality. The script uses 'tr' to convert all lower-case letters to upper, like this:

# echo 'abc' | tr [a-z] [A-Z]

...well, the output used to be 'ABC', but now it has become 'abc'. In other words, tr is just passing the characters through unchanged:

# echo 'abc' | tr [a-z] [A-Z]

I tried with the latest 1.16.0 'busybox' executable, same problem.

I rebooted with "pfix=ram" and 'tr' works. I ran my Woof script and 'tr' becomes broken. I have used this '2createpackages' script many times without this problem. I am so puzzled.

Ah, if I open a new terminal, 'tr' works again. More specifically, if I open another terminal in the same Woof directory as my script, 'tr' is broken. Open a terminal anywhere else, 'tr' works.

However, if I do it this way, tr comes good again:

# echo 'abc' | tr '[a-z]' '[A-Z]'

I put the single-quotes into my script, and it is now working. Yeah, but why?????


quoting tr arguments

From info coreutils 'tr invocation'
Username: Purplebelly
"Also [code]GNU `tr' does not support the System V syntax that uses square brackets to enclose ranges. Translations specified in that format sometimes work as expected, since the brackets are often transliterated to themselves. However, they should be avoided because they sometimes behave unexpectedly. For example, `tr -d '[0-9]'' deletes brackets as well as digits. [/code]

Tags: woof