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

The code you posted seems valid. Where's the problem? Did you forget the "do" on the line following "for"?

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

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

How about ksh?

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

Appreciate your suggestions.

Mark

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.

Thanks for your time - I will be trying your suggestions.

In ksh, you can use eval...

eval listname=\$${system}_list

Just store the value in varibale like below fashion! (\n seperated)
system="A
B
C"

and run through ur report analysis part!!!