If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > script translating characters

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-27-04, 15:15
timb25 timb25 is offline
Registered User
 
Join Date: Oct 2004
Posts: 6
Exclamation script translating characters

I have a script that runs to create a user account. I need the script to transfer the characters from lower case to upper case. The script acts very strangely. When I put in my input --> testuser it translates the entry to teLtuLer. by taking the 's' and making them upper case 'L'. What the??

Here is the script:

prompt_info()
{
echo "Enter NEW User ID (max 8 characters) --> \c"
read userid
export userid

echo "Userid for Unix: $userid"
USERID=`echo $userid | tr [a-z] [A-Z]`
echo "Userid for Oracle: $USERID"

echo "Press anykey to continue... \c"
read anykey
}

Here is the output on screen:
Enter NEW User ID (max 8 characters) --> testuser
Userid for Unix: testuser
Userid for Oracle: teLtuLer
Press anykey to continue...

I am really confused...

Thanks
-Tim
Reply With Quote
  #2 (permalink)  
Old 10-27-04, 16:05
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Try this,
USERID=`echo $userid | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`

On my SCO-Unix it works in this form

Here is the output on my screen:

Enter NEW User ID (max 8 characters) --> qwertasdfgyxcvb
Userid for Unix: qwertasdfgyxcvb
Userid for Oracle: QWERTASDFGYXCVB
Press anykey to continue...
__________________
Greetings from germany
Peter F.

Last edited by fla5do; 10-27-04 at 16:15.
Reply With Quote
  #3 (permalink)  
Old 10-27-04, 17:05
timb25 timb25 is offline
Registered User
 
Join Date: Oct 2004
Posts: 6
Smile thanks

Thanks...that worked great!!
Reply With Quote
  #4 (permalink)  
Old 10-27-04, 17:36
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
Quote:
Originally Posted by timb25
USERID=`echo $userid | tr [a-z] [A-Z]`
Are you sure you're using the square brackets correctly there? Try "man tr"...
Reply With Quote
  #5 (permalink)  
Old 10-28-04, 04:26
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Quote:
Originally Posted by timb25
I am really confused...
And well you might be!

[a-z] and [A-Z] are file expressions which your shell will glob out and expand if it finds any matching filenames in your working directory.

You can see what the shell is passing as tokens to tr by using echo.

e.g.

mkdir new; cd new; touch a b c; echo [a-z] [A-Z]

>>> a b c [A-Z]

If you don't want the expressions expanded before they are passed to tr, wrap the whole lot in single quotes, each individual token in double quotes or do away with the square brackets (because a-z is not a file expression whereas [a-z] is!)

tr '[a-z] [A-Z]'
tr "[a-z]" "[A-Z]"
tr a-z A-Z

I'm sure there are situations where you might want to use any one of the above methods depending on how 'clever' you're trying to be at the time.

HTH
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On