--- Archaic <[EMAIL PROTECTED]> 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.

The bash (1) manpage calls this indirection; it is described in the section
Parameter Expansion. Basically, if your variable holds the name of another
variable, you can precede the first variable name by an exclamation point to
expand the second variable. Here's an example that probably makes it clear:

$ echo "$USER"
chaotic
$ username_var="USER"
$ echo ${username_var}
USER
$ echo ${!username_var}
chaotic

Applying this to your example, I would do this:

eth0_onboot=yes
eth1_onboot=no

mknet ()
{
  net_dir=/etc/sysconfig/network-devices/ifconfig.$1
  mkdir -p $net_dir
  onboot_answer="${1}_onboot"
  onboot_answer="${!onboot_answer}"
  echo "ONBOOT=${onboot_answer}" >$net_dir/$2
# ...
}

The first assignment of onboot_answer will hold a variable name like
"eth0_onboot" or "eth1_onboot", then the second assignment conceptually
"dereferences" this, so now $onboot_answer refers to the value, such as "yes"
or "no".



                
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
-- 
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