![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing a variable inside a variable to a function | KingVikram | UNIX for Dummies Questions & Answers | 2 | 01-14-2008 05:28 PM |
| direction symbol in a variable as part of the command | peterloo | Shell Programming and Scripting | 5 | 12-06-2007 04:25 PM |
| Repacing part of string with a variable | divz | Shell Programming and Scripting | 4 | 07-18-2007 10:09 PM |
| Replace variable with a user defined variable | ce124 | Shell Programming and Scripting | 1 | 04-15-2007 11:56 AM |
| ksh: A part of variable A's name is inside of variable B, how to update A? | pa3be | Shell Programming and Scripting | 4 | 03-30-2005 08:29 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
variable part of variable name
Greetings
I am having a hard time trying to figure out how to use a variable as part of another variables name. For instance: A="PRE" eval ${A}_DAY=`date +%d` echo ${A}_DAY echo $PRE_DAY output: PRE_DAY 25 I would appreciate some help with this. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Hi,
I'm not sure this answer suits to your request (if you meant "how to display/store or use the resulting value", then this should help...). First, the 2 first lines sound correct for both defining a variable and assigning a value to it: me@host> A="PRE" me@host> eval ${A}_DAY=`date +%d` In order to solve this kind of trouble, I usually use this kind of syntax: me@host> DAY_VALUE=$(unalias echo; eval echo $"${A}_DAY") me@host> echo ${DAY_VALUE} me@host> 25 Hope it helps, Christophe |
|
#3
|
||||
|
||||
|
Quote:
echo $(eval echo \$${A}_DAY) eval echo "\$${A}_DAY" Thank You for your answer |
||||
| Google The UNIX and Linux Forums |