[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

bash question: reporting a variable named within a variable



Hello,

This isn't exactly a debian-specific question, but I'm not sure where
else to turn.

I'm writing a bash script wherein I have a list of variables of which I
want to return the values. A script representative of what I am trying
to do would be like this:


#!/bin/bash

FOO=bar
BLAH=blarg

for var in FOO BLAH ; do
	echo $var = $"$var" #this part is messed up
done
#end


The script above returns:

FOO = FOO
BLAH = BLAH

...but what I want it to return is

FOO = bar
BLAH = blarg

so obviously I need to change the $"$var" to something else, but I'm at
a loss as to what. I've tried various combinations of quotes, dollar
signs, curly braces, backticks, and pounding myself on the head, but to
no avail. :)

Now, I know I could just take everything out of the for loop, and echo
each variable individually, but in the real script I'm writing, the list
of variables is rather long and I'd rather keep it wrapped up.

Can anyone give me a hand with this, or am I just crazy? ;-)

Thanks,
Corey



Reply to: