![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 05:55 PM |
| Substitution in a variable | spragueg | UNIX for Advanced & Expert Users | 3 | 10-18-2001 06:14 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
The code you posted seems valid. Where's the problem? Did you forget the "do" on the line following "for"?
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
How about ksh?
Not sayng I can't change shells but everything so far was done in ksh. Appreciate your suggestions. Mark |
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
|||
|
|||
|
Thanks for your time - I will be trying your suggestions.
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|