Jump to content
Sign in to follow this  
Apoc

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

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...