Jump to content

variables within variables [solved]


Recommended Posts

hello,

 

I have a little problem. I have a file which looks like this:

 

NAMEA 12

NAMEB 53

NAMEC 10

NAMED 8

 

I process this using a little sed and awk to produce:

 

export NAMEA=12

 

which is run in the script using ` (aka funny quotes)

 

This sets up my variables nicely, now in the script i don't know what each od the variables will be called so i do a little for loop and reprocess the file i.e.:

 

for variable $(cat file | awk ' { print $1 } ')
do
 echo ${variable}
 echo $`echo ${variable}`
done

 

What i would like to do is the second line, i want to be able to set up a variable:

 

NAMEA=12

 

then loop through and echo NAMEA without knowing what it is called if that makes sense.

Edited by Apoc
Link to comment
Share on other sites

i have a solution but i think it is a bad way of doing this..

 

when i get my $variable i can do this:

 

VALUE=`env | grep $variable | awk -F= ' { print $2 } '`

 

I don't like calling env everytime though.. ideas?

Link to comment
Share on other sites

I'm not sure I really understand your question. Does this help you?

for variable $(cat file | awk '{print $1}')
do
echo ${variable} = $(eval echo \$${variable})
done

 

Yves.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...