Summary: Peculiar behaviour of tr

From: sa_venkatesan@chennai.tcs.co.in
Date: Sat Aug 12 2000 - 00:07:22 CDT


Thanks all for helping me to post the quickest summary on the list. Thanks to
Jonathan Ross in particular and Bruss Zimmer for his inputs.

My Original Post:

--> Hi all,
-->
--> When I was doing a little bit of shell scripting I came across this strange
--> behaviour of tr.
-->
--> For the same input, its output changes!! (the only change was the current
--> directory). I could not figure out why this is so? Ofcourse, quoting the
--> range does solve the problem. But I want to know the cause for this weird
--> behaviour.
-->
--> See this output
-->
--> $ echo venkat | tr [a-z] [A-Z]
--> VENKAT
--> $ cd /usr
--> $ echo venkat | tr [a-z] [A-Z]
--> venkXt
--> $
-->
--> I have tested this on Solaris 2.5.1 (sparc) machine it works fine. But on
other
--> versions 2.6, Solaris 7 & Solaris 8 versions give the same output as above.
-->
--> TIA. I will summarise.
-->
--> venkat

The problem is with the current directory. (In problem solving, start from the
place where you least expect - Murphy).

It is the shell behaviour (and that too normal) that is the cause for it. It is
me who is weird!

The problem is shell will expand the range first (because it is not quoted) and
tr [a-z] [A-Z] will be expanded to tr [a-z] X (because there is a directory
called X in the /usr directory). And it obviously transforms the character a to
X. If we try in a directory which has three single character file names, then
tr will report error.

Then how does it work in Solaris 2.5.1? Obviously there is no X directory in
/usr. All X binaries are in /usr/openwin itself.

Thanks again

venkat

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
"Contents of this E-Mail message are confidential, proprietary and privileged
and are intended for the addressee(s) only. Any unauthorised dissemination,
publication transfer or use of the contents of this message, with or without
modification(s) is punishable under the relevant law."
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tata Consultancy Services
www.tcs.com

S
U BEFORE POSTING please READ the FAQ located at
N ftp://ftp.cs.toronto.edu/pub/jdd/sun-managers/faq
. and the list POLICY statement located at
M ftp://ftp.cs.toronto.edu/pub/jdd/sun-managers/policy
A To submit questions/summaries to this list send your email message to:
N sun-managers@ececs.uc.edu
A To unsubscribe from this list please send an email message to:
G majordomo@sunmanagers.ececs.uc.edu
E and in the BODY type:
R unsubscribe sun-managers
S Or
. unsubscribe sun-managers original@subscription.address
L To view an archive of this list please visit:
I http://www.latech.edu/sunman.html
S
T



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:14:14 CDT