Results 1 to 5 of 5

Thread: bash tr help

  1. #1
    Join Date
    Dec 2003
    Posts
    5

    Angry Unanswered: bash tr help

    I am learning unix scripting in a Red Hat environment and have followed the examples in the book with no problems. I however am having problems with the method that the book gives for translating the case in a variable.

    The example is as follows:

    read answer
    answer=$(cat $answer | tr '[A-Z]' '[a-z]')

    when ever I run this I get an error message that tells me the contents of $answer is not a valid file.

    Any help would be appreciated.

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525

    Re: bash tr help

    Originally posted by Dahn
    read answer
    answer=$(cat $answer | tr '[A-Z]' '[a-z]')

    when ever I run this I get an error message that tells me the contents of $answer is not a valid file.

    Any help would be appreciated.
    'cat' is expecting a filename as an argument - use 'echo'. You could also use 'typeset -u' to decalre a variable as uppercase text.

    e.g.

    typeset -u answer=$answer

    Beware of scope when using this method as for example, variables declared in functions will only be set within that function.

  3. #3
    Join Date
    Dec 2003
    Posts
    5

    Re: bash tr help

    Originally posted by Damian Ibbotson
    'cat' is expecting a filename as an argument - use 'echo'. You could also use 'typeset -u' to decalre a variable as uppercase text.

    e.g.

    typeset -u answer=$answer

    Beware of scope when using this method as for example, variables declared in functions will only be set within that function.

  4. #4
    Join Date
    Dec 2003
    Posts
    5

    Re: bash tr help

    Originally posted by Damian Ibbotson
    'cat' is expecting a filename as an argument - use 'echo'. You could also use 'typeset -u' to decalre a variable as uppercase text.

    e.g.

    typeset -u answer=$answer

    Beware of scope when using this method as for example, variables declared in functions will only be set within that function.
    Thanks for the reply. Will typeset work on any unix or only on Linux.

    Dahn

  5. #5
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525

    Re: bash tr help

    Originally posted by Dahn
    Thanks for the reply. Will typeset work on any unix or only on Linux.
    I'm not sure about ANY flavour but it'll certainly be compatible with the Bourne type shells (sh, ksh, bash...).

Posting Permissions

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