Apoc Posted June 21, 2005 Report Share Posted June 21, 2005 (edited) 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 June 21, 2005 by Apoc Quote Link to comment Share on other sites More sharing options...
Apoc Posted June 21, 2005 Author Report Share Posted June 21, 2005 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? Quote Link to comment Share on other sites More sharing options...
theYinYeti Posted June 21, 2005 Report Share Posted June 21, 2005 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. Quote Link to comment Share on other sites More sharing options...
Apoc Posted June 21, 2005 Author Report Share Posted June 21, 2005 echo ${variable} = $(eval echo \$${variable}) EXACTLY what i wanted.. Thanks a lot. Apoc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.