[wplug] bash variable help

Poyner, Brandon bpoyner at ccac.edu
Wed Feb 18 11:09:45 EST 2004


Another option, not as elegant as eval but sometimes practical, is to do
a case.

testfunc() {
        case ${1} in
                1)
                        which_var=${var1}
                        ;;
                2)
                        which_var=${var2}
                        ;;
                3)
                        which_var=${var3}
                        ;;
                *)
                        ;;
        esac
        echo $which_var
}

Brandon Poyner
Network Engineer II
CCAC - College Office
412-237-3086


-----Original Message-----
From: Rick Smith [mailto:rick at rbsmith.com] 
Sent: Wednesday, February 18, 2004 12:08 PM
To: wplug at wplug.org
Subject: Re: [wplug] bash variable help


Try:
eval which_var=\$var$1

eval does a two pass.  The \$ will translate to $ on the first pass,
and expand the way you want on the second.



More information about the wplug mailing list