Variable substitution

Variable substitution

am 27.08.2007 12:30:13 von Dattu

Hi All,
I have the below requirement. I Checked in google and
few of the sites and groups and unable to find the solution.


Requirement is as follows.

===
A="XYZ"
B="ABC"
XYZ_ABC="Status_300"

I would like to construct the string XYZ_ABC using $A abd $B and print
the value of $XYZ_ABC

It's like

> echo $A_$B
XYZ_ABC

Using the above values of $A_$B

Print the value of $XYZ_ABC


Something like

> echo $ ( $A_$B) should print the value "Status_300"


Thanks in advance,
Rao

Re: Variable substitution

am 27.08.2007 12:54:27 von cichomitiko

"Dattu" wrote ...
[...]
> Requirement is as follows.
>
> ===
> A="XYZ"
> B="ABC"
> XYZ_ABC="Status_300"
>
> I would like to construct the string XYZ_ABC using $A abd $B and print
> the value of $XYZ_ABC
>
> It's like
>
> > echo $A_$B
> XYZ_ABC
>
> Using the above values of $A_$B
>
> Print the value of $XYZ_ABC
[...]

bash 3.2.25(16) $ A="XYZ"
bash 3.2.25(16) $ B="ABC"
bash 3.2.25(16) $ XYZ_ABC="Status_300"
bash 3.2.25(16) $ eval "echo \$${A}_${B}"
Status_300


Dimitre

Re: Variable substitution

am 27.08.2007 12:58:49 von Dattu

Thanks a lot for the reply ....


Any other ways to caliculate the same ?


Thanks,
Rao

Re: Variable substitution

am 27.08.2007 13:01:31 von Janis Papanagnou

On 27 Aug., 13:58, Dattu wrote:
> Thanks a lot for the reply ....
>
> Any other ways to caliculate the same ?

What "the same"? Please quote context!

And what's wrong with the posted solution?

>
> Thanks,
> Rao

Re: Variable substitution

am 27.08.2007 13:07:42 von Dattu

Hi Janis,

Sorry for the confusion.

On Aug 27, 4:01 pm, Janis wrote:
> On 27 Aug., 13:58, Dattu wrote:
>
> > Thanks a lot for the reply ....
>
> > Any other ways to caliculate the same ?

> What "the same"? Please quote context!

"the same" means for the posted problem as above(Original post).

> And what's wrong with the posted solution?

Nothing worng with solution. It's working fine for me. But, I would
like to know the other kinds of solutions for the problem.

>
>
>
>
>
> > Thanks,
> > Rao- Hide quoted text -
>
> - Show quoted text -

Re: Variable substitution

am 27.08.2007 13:23:38 von cichomitiko

"Dattu" wrote in message ...
[...]
>> "Dattu" wrote ...
>> [...]
>>> Requirement is as follows.
>>>
>>> ===
>>> A="XYZ"
>>> B="ABC"
>>> XYZ_ABC="Status_300"
>>>
>>> I would like to construct the string XYZ_ABC using $A abd $B and print
>>> the value of $XYZ_ABC
>>>
>>> It's like
>>>
>> >> echo $A_$B
>>> XYZ_ABC
>>>
>>> Using the above values of $A_$B
>>>
>>> Print the value of $XYZ_ABC
>> [...]
>>
>> bash 3.2.25(16) $ A="XYZ"
>> bash 3.2.25(16) $ B="ABC"
>> bash 3.2.25(16) $ XYZ_ABC="Status_300"
>> bash 3.2.25(16) $ eval "echo \$${A}_${B}"
>> Status_300
[...]

> But, I would
> like to know the other kinds of solutions for the problem.

zsh 4.3.2 % eval print $"${!A}_${!B}"
eval print $"${A="XYZ"}_${B="ABC"}"
Status_300


Dimitre

Re: Variable substitution

am 27.08.2007 17:34:39 von Janis Papanagnou

On 27 Aug., 14:07, Dattu wrote:
> Hi Janis,
>
> Sorry for the confusion.
>
> On Aug 27, 4:01 pm, Janis wrote:
>
> > On 27 Aug., 13:58, Dattu wrote:
>
> > > Thanks a lot for the reply ....
>
> > > Any other ways to caliculate the same ?
> > What "the same"? Please quote context!
>
> "the same" means for the posted problem as above(Original post).

I thought so, but since this is Usenet and not a web forum you
should always quote all necessary context.

>
> > And what's wrong with the posted solution?
>
> Nothing worng with solution. It's working fine for me. But, I would
> like to know the other kinds of solutions for the problem.

Using eval is the standard way for this kind of "meta-indirection".

Janis

>
>
>
> > > Thanks,
> > > Rao- Hide quoted text -
>
> > - Show quoted text -