The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reference Variable cchaloux Shell Programming and Scripting 18 10-03-2007 06:58 AM
How to reference a variable within sed? rockysfr Shell Programming and Scripting 1 06-27-2007 01:04 AM
KSH variable substitution tipsy Shell Programming and Scripting 5 08-14-2006 02:07 PM
Variable Substitution garak Shell Programming and Scripting 2 03-16-2006 04:55 PM
Substitution in a variable spragueg UNIX for Advanced & Expert Users 3 10-18-2001 06:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-01-2004
Registered User
 

Join Date: Jul 2004
Posts: 4
Stumble this Post!
Angry Unix Variable Reference and Substitution

I can't seem to make what appears to be a simple substitution.

I want to define a list of systems for which daily reports need to be filed

systems="systemA systemC systemZ"

I then want to run a loop

for i in ${systems}

Analyze statistics
Create the reports


mailx
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-01-2004
Registered User
 

Join Date: May 2004
Location: Hawaii
Posts: 37
Stumble this Post!
The code you posted seems valid. Where's the problem? Did you forget the "do" on the line following "for"?
Reply With Quote
  #3 (permalink)  
Old 07-02-2004
Registered User
 

Join Date: Jul 2004
Posts: 4
Stumble this Post!
Sorry - first time on the board and I did not finish my problem before I accidentally hit a key and posted it. Thanks for reply

Here is what I can not do. For each of those systems, I neeed to email the reports using mailx to different recipients.

systemA_list="me you"
systemB_list="me you him"
systemZ_list="you him"

Therefore, in the for do loop, I need to use the current value of the systems variable that is being processed to reference the correct ${systems}_list and poulate the mailx command.

It is that variable substitution or reference that I can not seem to acheive. it always tells me it can not find systemA_list. Not sure if it even knows I am trying to make it a variable.

Thanks
Mark
Reply With Quote
  #4 (permalink)  
Old 07-02-2004
Registered User
 

Join Date: May 2004
Location: Hawaii
Posts: 37
Stumble this Post!
With bash, you can use the following construct to use the contents of a variable as the name of another variable, doing in effect a double expansion:

${!systems}

If systems contains "systemA_list", then it will instead expand the value of $systemA_list. It sounds like you have to do something like this:

system=systemA

listname=${system}_list #put name of required variable in $listname

list=${!listname} # expand $listname twice, giving the value of $systemA_list
Reply With Quote
  #5 (permalink)  
Old 07-02-2004
Registered User
 

Join Date: Jul 2004
Posts: 4
Stumble this Post!
How about ksh?

Not sayng I can't change shells but everything so far was done in ksh.

Appreciate your suggestions.

Mark
Reply With Quote
  #6 (permalink)  
Old 07-02-2004
Registered User
 

Join Date: May 2004
Location: Hawaii
Posts: 37
Stumble this Post!
I checked the ksh manual and couldn't find anything about indirect substitution, so I guess you're out of luck. I'm no ksh regular, though.
Reply With Quote
  #7 (permalink)  
Old 07-02-2004
Registered User
 

Join Date: Jul 2004
Posts: 4
Stumble this Post!
Thanks for your time - I will be trying your suggestions.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0