Nested Variable for loop questions

Hello,
Got a strange one here I have been working on and can not find a
way around it...Here is what I got:

HOSTNAME=`hostname | tr [a-z] [A_Z]`

GOLIATH="suzy charlie bob leroy"

eval echo "\$${HOSTNAME}"


If I run this on a server named goliath, it prints what I expect:
"suzy charlie bob leroy"

But how do I get it into a for loop?

for i in `eval echo "\$${HOSTNAME}"`
do
echo $i
done

does not work?

Any suggestions on how to run a for loop with a nested variable?

Thanks in advance.

Sincerely,
Sunckell
sunckell [ Di, 27 November 2007 20:16 ] [ ID #1879551 ]

Re: Nested Variable for loop questions

sunckell wrote:
> Hello,
> Got a strange one here I have been working on and can not find a
> way around it...Here is what I got:
>
> HOSTNAME=`hostname | tr [a-z] [A_Z]`
>
> GOLIATH="suzy charlie bob leroy"
>
> eval echo "\$${HOSTNAME}"
>
>
> If I run this on a server named goliath, it prints what I expect:
> "suzy charlie bob leroy"
>
> But how do I get it into a for loop?
>
> for i in `eval echo "\$${HOSTNAME}"`
> do
> echo $i
> done
>
> does not work?
>
> Any suggestions on how to run a for loop with a nested variable?

How about...

HOSTNAME=$(hostname | tr 'a-z' 'A-Z')
GOLIATH="suzy charlie bob leroy"
eval set - \$$HOSTNAME
for i ; do echo $i ; done


Janis

>
> Thanks in advance.
>
> Sincerely,
> Sunckell
Janis Papanagnou [ Di, 27 November 2007 20:38 ] [ ID #1879553 ]

Re: Nested Variable for loop questions

On Nov 27, 2:38 pm, Janis Papanagnou <Janis_Papanag... [at] hotmail.com>
wrote:
> sunckell wrote:
> > Hello,
> > Got a strange one here I have been working on and can not find a
> > way around it...Here is what I got:
>
> > HOSTNAME=`hostname | tr [a-z] [A_Z]`
>
> > GOLIATH="suzy charlie bob leroy"
>
> > eval echo "\$${HOSTNAME}"
>
> > If I run this on a server named goliath, it prints what I expect:
> > "suzy charlie bob leroy"
>
> > But how do I get it into a for loop?
>
> > for i in `eval echo "\$${HOSTNAME}"`
> > do
> > echo $i
> > done
>
> > does not work?
>
> > Any suggestions on how to run a for loop with a nested variable?
>
> How about...
>
> HOSTNAME=$(hostname | tr 'a-z' 'A-Z')
> GOLIATH="suzy charlie bob leroy"
> eval set - \$$HOSTNAME
> for i ; do echo $i ; done
>
> Janis
>
>
>
> > Thanks in advance.
>
> > Sincerely,
> > Sunckell

Yeah that worked....

gracias
sunckell [ Di, 27 November 2007 21:15 ] [ ID #1879555 ]
Linux » comp.unix.shell » Nested Variable for loop questions

Vorheriges Thema: shell redirect
Nächstes Thema: question about variable in case structure