D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

[LUG] Fwd: Bash: pointers?

 

try this out

a=1;
echo $a;
b=2;
echo $b;
device=a;
echo $device;
export a
export b
export device
bash -c "echo \$$device"
device=b
bash -c "echo \$$device"
b="hello"
bash -c "echo \$$device"

if you change echo to your ifconfig command i imagine it would do what
you want. something like this (which i haven't tested because i'm
using my network)

eth0=[insert values here];
echo $eth0;
eth1=[insert values here];
echo $eth1;
device=eth0;
echo $device;
export eth0
export eth1
export device
bash -c "ifconfig \$$device"
device=eth1
bash -c "ifconfig \$$device"


On 2/23/07, Simon Williams <systemparadox@xxxxxxxxxxxxxx> wrote:
> For some strange reason I keep encountering this problem when dealing
> with network devices.
>
> Basically I have shell variables set such as
> eth0="eth0 up 192.168.0.1 netmask 255.255.255.0"
>
> which are used something like:
> ifconfig $eth0
>
> What I want to do is change the above line to something like:
> ifconfig ${$device}
>
> where device=eth0, so that bash substitutes it to give:
> ifconfig $eth0
>
> Anyone know if this sort of thing is possible? I have no idea what it
> would actually be called.
>
> Thanks
> Simon
>
> --
> The Mailing List for the Devon & Cornwall LUG
> http://mailman.dclug.org.uk/listinfo/list
> FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html
>

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html