[wplug] bash variable help
Henry Umansky
hmust2+ at pitt.edu
Wed Feb 18 10:31:13 EST 2004
I'm having a lot of trouble writing a bash script. Here's what I want to
do:
I have a file that contains multple variables
#file1
var1="value1"
var2="value2"
var3="value3"
Then I have another file that sources file1 and has a function that takes
one argument. The argument can be either a 1, 2, or 3. That function,
depending on the argument, will use var1, var2, var3, respectively.
#file 2
function() {
which_var = "var${1}"
}
Now, the variable $which_var either has a value of "var1", "var2", or
"var3". How would I use $which_var to extract the value of var1, var2,
etc, so I get the value "value1", "value2", or "value3" instead of the
value "var1", "var2", or "var3". Unfortunately, I can't pass a var1, a
var2, or a var3 to the function instead of 1, 2, 3, because the real script
I'm writing will not know the variable name ahead of time. Any help would
be much appreciated.
-Henry
More information about the wplug
mailing list