Apoc Posted June 21, 2005 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 Link to comment Share on other sites More sharing options...
Apoc Posted June 21, 2005 Author 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? Link to comment Share on other sites More sharing options...
theYinYeti Posted June 21, 2005 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. Link to comment Share on other sites More sharing options...
Apoc Posted June 21, 2005 Author Share Posted June 21, 2005 echo ${variable} = $(eval echo \$${variable}) EXACTLY what i wanted.. Thanks a lot. Apoc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now