Creating a shell variable name from a variable's value, aka a hash


Use the eval command to take the value assigned to a shell variable and create a new variable named the same as that value.
a=red
eval $a=b
echo $red
b

Here's another way to achieve a similar result:

house=4
x=house
echo ${!x}
4

11/19/2007
Updated 01/19/2009