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 > bash tr help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-03-03, 23:25
Dahn Dahn is offline
Registered User
 
Join Date: Dec 2003
Posts: 5
Angry 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.
Reply With Quote
  #2 (permalink)  
Old 12-04-03, 05:00
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: bash tr help

Quote:
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.
Reply With Quote
  #3 (permalink)  
Old 12-04-03, 12:22
Dahn Dahn is offline
Registered User
 
Join Date: Dec 2003
Posts: 5
Re: bash tr help

Quote:
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.
Reply With Quote
  #4 (permalink)  
Old 12-04-03, 12:24
Dahn Dahn is offline
Registered User
 
Join Date: Dec 2003
Posts: 5
Re: bash tr help

Quote:
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
Reply With Quote
  #5 (permalink)  
Old 12-05-03, 04:39
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: bash tr help

Quote:
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...).
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