Archaic wrote:

I'm writing a function that will script the generation of the ifconfig
subdirs. The problem is that I'm trying to expand the value of a
variable where the variable name itself is a variable. EX:

eth0_onboot=yes
eth1_onboot=no

The relevant part of the function is this:

mknet ()
{
 net_dir=/etc/sysconfig/network-devices/ifconfig.$1
 mkdir $net_dir
 echo "ONBOOT=$1_onboot" >$net_dir/$2
<..>

and the function is called as 'mknet <device> <service>' All the
information as to what to put into the fields is pre-defined as exported
variables.

The output of the above echo is "ONBOOT=eth0_onboot" (assuming eth0 was
the device given in the call to mknet).

I can't seem to find a way to expand $1_onboot and then get the value of
the expanded variable name.

Any ideas?

Is this what you're looking for?

Assume that the value of a variable is the name of a second variable. Is it somehow possible to retrieve the value of this second variable from the first one? For example, if a=letter_of_alphabet and letter_of_alphabet=z, can a reference to a return z? This can indeed be done, and it is called an indirect reference. It uses the unusual eval var1=\$$var2 notation.

This comes from Section 9.5 of "Advanced Bash-Scripting Guide." I also think I remember that it can take the form of A=SOMETHING, B=$($A). If I'm right there are some examples in the bootscripts--don't know which ones. In fact, I downloaded that guide so that I could understand some of the scripts that I was putting on my box while I was building.

That scripting guide is really great. After the quote that I provided, it gives some scripting examples.

Dan


--
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to