Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot, bind-address mysql multiple, sanibleone xxxx, ftp://192.168.100.100/, www.xxxcon

Links

XODOX
Impressum

#1: Variable substitution

Posted on 2007-08-27 12:30:13 by 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

Report this message

#2: Re: Variable substitution

Posted on 2007-08-27 12:54:27 by cichomitiko

"Dattu" <datteswararao@gmail.com> 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

Report this message

#3: Re: Variable substitution

Posted on 2007-08-27 12:58:49 by Dattu

Thanks a lot for the reply ....


Any other ways to caliculate the same ?


Thanks,
Rao

Report this message

#4: Re: Variable substitution

Posted on 2007-08-27 13:01:31 by Janis Papanagnou

On 27 Aug., 13:58, Dattu <datteswara...@gmail.com> 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

Report this message

#5: Re: Variable substitution

Posted on 2007-08-27 13:07:42 by Dattu

Hi Janis,

Sorry for the confusion.

On Aug 27, 4:01 pm, Janis <janis_papanag...@hotmail.com> wrote:
> On 27 Aug., 13:58, Dattu <datteswara...@gmail.com> 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 -

Report this message

#6: Re: Variable substitution

Posted on 2007-08-27 13:23:38 by 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

Report this message

#7: Re: Variable substitution

Posted on 2007-08-27 17:34:39 by Janis Papanagnou

On 27 Aug., 14:07, Dattu <datteswara...@gmail.com> wrote:
> Hi Janis,
>
> Sorry for the confusion.
>
> On Aug 27, 4:01 pm, Janis <janis_papanag...@hotmail.com> wrote:
>
> > On 27 Aug., 13:58, Dattu <datteswara...@gmail.com> 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 -

Report this message