LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   function showing a list of variable and value: (dynamic variable name) (http://www.linuxquestions.org/questions/linux-newbie-8/function-showing-a-list-of-variable-and-value-dynamic-variable-name-671141/)

budhax 09-19-2008 05:44 PM

function showing a list of variable and value: (dynamic variable name)
 
Hello,
I would like to build a function showing a list of variables like:
variable name : [variable value]
but, respectfully, Mr BASH cannot understand this: ${$name}

Is there a way to do that (using a FOR loop and a list VAR=CN1 ...)?
Thanks

Here my code:

Code:

#^!/bin/bash

fARP=fARP
fCAP=fCAP
fIVS=fIVS
fPSK=fPSK
fXOR=fXOR
#
CN1=eth1
VC1=rtap0
CN2=rausb0
VC2=wifi0
#
RTE=200
MEID=IPW22
DICO=Dic.LOG
IP0=192.168.1.100
IP1=192.168.1.101
MAC=50:41:32:23:14:05
#
VAR="CN1 VC1 CN2 VC2 RTE MEID DICO MAC"

function ShowVAR () {
        echo var_name : [var_value]
        for name in $VAR; do
                value=${$name}
                echo  "$name : $value"
        done
}


budhax 09-19-2008 07:05 PM

I found a solution (googleling with: bash dynamic variable name).

Code:

function ShowVAR () {
        echo var_name : [var_value]
        for name in $VAR; do
                #value=${$name}
                echo  "$name : ${!name}"
        done
}

Thanks and regards.

Source:
http://www.commentcamarche.net/forum...bleme-variable


All times are GMT -5. The time now is 01:24 PM.