The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Dynamic variable values ronnie_uk UNIX for Dummies Questions & Answers 3 07-11-2008 10:03 AM
comparing values of same variable coolkid Shell Programming and Scripting 2 05-27-2008 06:45 PM
getting values from variable in a loop kriuz Shell Programming and Scripting 3 01-22-2008 05:50 PM
Substitute variable values John Rihn Shell Programming and Scripting 12 03-15-2006 10:40 PM
Storing values in variable matrixmadhan Shell Programming and Scripting 1 04-01-2005 02:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-19-2008
anilacharya4u anilacharya4u is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
How to get the values from a variable having variable name

In shell script how to do the following .......................

For example
I have following 3 variables

VARIABLE_DYNAMIC
JOB_NP_22="ABCD"
JOB_NP_88="HELLO"

based on the value in VARIABLE_DYNAMIC the particular variable value should be displayed
--------------------------------------------------------------
(I) If value of VARIABLE_DYNAMIC="JOB_NP_21"
so by some way i should get value of "JOB_NP_21" i.e ABCD as output

(II) If value of VARIABLE_DYNAMIC="JOB_NP_88"
so by some way i should get value of "JOB_NP_88" i.e HELLO as output

we can retrive variable directly $VARIABLE_DYNAMIC
but as the value in VARIABLE_DYNAMIC is coming dynamically..... i am facing problems in retriving values of the variable (JOB_NP_21 / JOB_NP_88)

Please tell me how to do that

Last edited by anilacharya4u; 09-19-2008 at 06:44 AM..
  #2 (permalink)  
Old 09-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652

Code:
eval echo \$$VARIABLE_DYNAMIC

  #3 (permalink)  
Old 09-19-2008
subhendu81 subhendu81 is offline
Registered User
  
 

Join Date: Sep 2008
Location: mumbai
Posts: 78
hi anil,

do u want to give the variable as user input or is shud take dynamically?
  #4 (permalink)  
Old 09-19-2008
anilacharya4u anilacharya4u is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
Unhappy

hi era / subhendu ,

can u please tell me how do i assign the value which i get from this
eval echo \$$VARIABLE_DYNAMIC

to a variable

See the JOB_NP_22 and JOB_NP_88 are actually arrays...
The actual strucure of my variable would be
JOB_NP_22[0]=a,b
JOB_NP_22[1]=c,d

JOB_NP_88[0]=m,n
JOB_NP_88[1]=o,p

i will get these values and loop through the elements ...

Basically the String JOB_NP_22 and JOB_NP_88
will be created partly by "JOB_NP" ( this is hard coded ) and
22 /88 passed as paramters so its a combination of 2

However my hardcode variable loop works
for (( cnt = 0 ; cnt < ${#JOB_NP_22[@]} ; cnt++ ))
do
echo ${JOB_NP_22[cnt]}
done



Need to replace this hardcoded loop and make it dynamic
So please tell me how to assign it to an array and use the array across in my code for looping

Last edited by anilacharya4u; 09-19-2008 at 07:19 AM..
  #5 (permalink)  
Old 09-19-2008
subhendu81 subhendu81 is offline
Registered User
  
 

Join Date: Sep 2008
Location: mumbai
Posts: 78
hi anil,

try the following

set -A JOB_NP_22 a,b c,d

while [ $i -lt 2 ]
do
print ${JOB_NP_22[$i]}
((i=i+1))
done


and also do the same for variable
"JOB_NP_88"
  #6 (permalink)  
Old 09-19-2008
anilacharya4u anilacharya4u is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
Unhappy

Hi,

The array looping for JOB_NP_22 / JOB_NP_88 part is done...

Problem is with the initial part for retriving values i.e
taking value of variable name in VARIABLE_DYNAMIC String


Can the value which we get from this
eval echo \$$VARIABLE_DYNAMIC
be put in array
It is required in the array for loopingthrough elements
  #7 (permalink)  
Old 09-19-2008
subhendu81 subhendu81 is offline
Registered User
  
 

Join Date: Sep 2008
Location: mumbai
Posts: 78
anil plz make it clear...so that i will able to ans ur questions...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0