|
Home > Archive > Unix Shell > November 2007 > Nested Variable for loop questions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Nested Variable for loop questions
|
|
| sunckell 2007-11-27, 1:29 pm |
| 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
| |
| Janis Papanagnou 2007-11-27, 7:21 pm |
| 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
| |
| sunckell 2007-11-27, 7:21 pm |
| On Nov 27, 2:38 pm, Janis Papanagnou <Janis_Papanag...@hotmail.com>
wrote:[vbcol=seagreen]
> sunckell wrote:
>
>
>
>
>
>
>
>
>
> How about...
>
> HOSTNAME=$(hostname | tr 'a-z' 'A-Z')
> GOLIATH="suzy charlie bob leroy"
> eval set - \$$HOSTNAME
> for i ; do echo $i ; done
>
> Janis
>
>
>
>
Yeah that worked....
gracias
|
|
|
|
|