Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    6

    Exclamation Unanswered: 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

  2. #2
    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...
    Last edited by fla5do; 10-27-04 at 17:15.
    Greetings from germany
    Peter F.

  3. #3
    Join Date
    Oct 2004
    Posts
    6

    Smile thanks

    Thanks...that worked great!!

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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"...

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •