Computing.Net > Forums > Unix > ADDRESS CONTENT VARIABLE csh

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ADDRESS CONTENT VARIABLE csh

Reply to Message Icon

Name: sobolev
Date: March 16, 2009 at 04:42:46 Pacific
OS: UNIX CSH
Subcategory: General
Comment:

By using a csh, I want to address a variable content whose name is/matches the content of a given other variable.
i.e.
set name=´sam´
set ${name}_age=´27´

So, by typing: echo ${name}_age
I correctly obtain: sam_age
By typing: echo $sam_age
or echo ${sam_age}
I correctly obtain: 27

But how can I obtain "27" by using ${name} instead of "sam"?
The following instruction does not work!
echo ${`echo ${name}_age`}

Any helps will be accepted!
Thanks a lot!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 16, 2009 at 09:25:16 Pacific
Reply:

The eval command is typically used for this:

#!/bin/csh

set name='sam'
set eval ${name}_age='27'

echo "sam is: ${sam_age}"


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: ADDRESS CONTENT VARIABLE csh

CSH Runtime Arguments www.computing.net/answers/unix/csh-runtime-arguments/3825.html

csh script && positional parameters www.computing.net/answers/unix/csh-script-ampamp-positional-parameters/1595.html

ksh - variable of a variable name? www.computing.net/answers/unix/ksh-variable-of-a-variable-name/6821.html