[wplug] bash variable help

Henry Umansky hmust2+ at pitt.edu
Wed Feb 18 10:45:09 EST 2004


To clarify a bit, PHP does exactly what I want to do.  Now the question is, 
how can I make Bash do it.  The following page shows what I was talking 
about:

http://www.php.net/manual/en/language.variables.variable.php

-Henry

--On Wednesday, February 18, 2004 10:31 AM -0500 Henry Umansky 
<hmust2+ at pitt.edu> wrote:r

> 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
> _______________________________________________
> wplug mailing list
> wplug at wplug.org
> http://www.wplug.org/mailman/listinfo/wplug







More information about the wplug mailing list