- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- tr scripts giving wrong results
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:10 AM
09-20-2002 06:10 AM
UPPERNAME=`print $NAME | tr [a-z] [A-Z]`
print $NAME
print $UPPERNAME
exit
Then touch a file called p in the directory you are executing from ie be in your home directory and touch p then execute the above script.
No translation occurs. change the p to an a and you get different results. My shell is ksh, seems to perform the same in sh.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:16 AM
09-20-2002 06:16 AM
Re: tr scripts giving wrong results
I though you were full of it, but you are right, this is what I got:
# ./io
bcwbird
BCWBIRD
# touch p
# ./io
bcwbird
bcwbird
# touch a
# ./io
tr: The combination of options and String parameters is not legal.
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
tr [ -cd | -cs | -d | -s ] [-A] String1
bcwbird
#
I'm gonna analize it, be back soon
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:16 AM
09-20-2002 06:16 AM
Re: tr scripts giving wrong results
I tried your script and it seems to work correctly. I'm a little confused. Are you passing the filename as a parameter to the script? I don't see how your script (as shown in your post) has anything to do with any file name.
Could it be that you have an alias in your shell for the letters 'a' or 'p' that could be throwing you off?
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:18 AM
09-20-2002 06:18 AM
Re: tr scripts giving wrong results
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:20 AM
09-20-2002 06:20 AM
SolutionYou need to put the TRANSLATION strings in QUOTES:
# cat ./io
#!/sbin/sh
NAME=bcwbird
UPPERNAME=`print $NAME | tr "[a-z]" "[A-Z]"`
print $NAME
print $UPPERNAME
# ./io
bcwbird
BCWBIRD
# rm p a
# ./io
bcwbird
BCWBIRD
# touch p
# ./io
bcwbird
BCWBIRD
# touch a
# ./io
bcwbird
BCWBIRD
#
The issue is the `` executing and translating characters.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:22 AM
09-20-2002 06:22 AM
Re: tr scripts giving wrong results
Try;
# UPPERNAME=`print $NAME | tr '[a-z]' '[A-Z]'`
...or...
UPPERNAME=`print $NAME | tr '[:lower:]' '[:upper:]'`
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:23 AM
09-20-2002 06:23 AM
Re: tr scripts giving wrong results
typeset -u UPPERNAME=$NAME
will work fine.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:23 AM
09-20-2002 06:23 AM
Re: tr scripts giving wrong results
tr [a-z] [A-Z] should read
tr "[a-z]" "[A-Z]"
Without the quotes, the shell matches [a-z] with the filename 'p' (or 'a') and so the first argument supplied to tr is the filename.
If you are simply converting a string to uppercase then a more efficient way is to declare an uppercase variable thus:-
typeset -u UPPERNAME
NAME=bcwbird
UPPERNAME=${NAME}
print ${UPPERNAME}
BCWBIRD
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:25 AM
09-20-2002 06:25 AM
Re: tr scripts giving wrong results
this is easier to show:
# rm a p
# echo a | tr [a-z] [A-Z]
A
# touch p
# echo a | tr [a-z] [A-Z]
a
# touch a
# echo a | tr [a-z] [A-Z]
tr: The combination of options and String parameters is not legal.
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
tr [ -cd | -cs | -d | -s ] [-A] String1
# echo a | tr "[a-z]" "[A-Z]"
A
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:25 AM
09-20-2002 06:25 AM
Re: tr scripts giving wrong results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2002 06:27 AM
09-20-2002 06:27 AM
Re: tr scripts giving wrong results
tr [a-z] [A-Z] becomes tr p ... when a matching file is found.
If you discipline yourself to use ${VAR} rather than $VAR and enclose almost all arguments in the appropriate quotes, you will see far fewer
unexpected behaviors in the shell.