Nested Variable for loop questions

Nested Variable for loop questions

am 27.11.2007 20:16:00 von sunckell

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

Re: Nested Variable for loop questions

am 27.11.2007 20:38:20 von Janis Papanagnou

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

Re: Nested Variable for loop questions

am 27.11.2007 21:15:08 von sunckell

On Nov 27, 2:38 pm, Janis Papanagnou
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