Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

translating uppercase to lowercase characters in a unix script 1

Status
Not open for further replies.

hugheskbh

Programmer
Dec 18, 2002
37
US
How would I translate uppercase characters to lowercase characters in a unix script? I need to translate incoming parms from upper to lower and back again.

Thanks
 
man tr
or:
cmdUp=`echo $cmd | awk ' {print toupper($0)}'`
cmdDown=`echo $cmd | awk ' {print tolower($0)}'`

 
In Korn shell, it's...
[tt]
typeset -u VARIABLE
typeset -l VARIABLE
[/tt]
...for upper and lower case respectively.
 
just to save you looking at the tr manpage

echo $STRING|tr '[:upper:]' '[:lower:]'
 
This is not working. My code is:

echo $STRING|tr '[:upper:]''[:lower:]'
cd /lawson/lawson/$1/$2src

but I keep getting this error:

sh @compilet DEV724 UB
tr: 0653-712 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

Help!!
 
echo $STRING|tr '[:upper:]' '[:lower:]'

NOTE: there should a space between quoated parameters to 'tr' [space between the inner ' '] vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Well, no errors this time, but it's still not working. I should get:

/lawson/lawson/dev724/ubsrc

but I'm getting:

/lawson/lawson/DEV724/UBsrc
 
well..... it works for me:

$ echo '/lawson/lawson/DEV724/UBsrc' |tr '[:upper:]' '[:lower:]'
/lawson/lawson/dev724/ubsrc
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I think the reason it's working for you is because the DEV724/UBSRC are paramaters coming in:

sh @compiletest DEV724 UB

But the code in the program to accept these parms are:

cd /lawson/lawson/$1/$2scr

Maybe it doesn't work with incoming parameters?
 
leaf=$(echo &quot;${1}/${2}scr&quot; | tr '[:upper:]' '[:lower:]')
echo &quot;leaf->[${leaf}]&quot;

cd /lawson/lawson/${leaf} vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
A star for overcomplication vlad..you know I love that stuff,
and sometimes it's even necessary ;)
 
thanks - glad to help! vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top