x=1
c1=string1
c2=string2
c3=string3
echo $c1
string1
I’d like to have the output be string1 by using something like:
echo $(c($x))
So later in the script I can increment the value of x and have it output string1, then string2 and string3.
Can anyone point me in the right direction?
See the Bash FAQ: How can I use variable variables (indirect variables, pointers, references) or associative arrays?
To quote their example:
To show how this is useful for your example:
If, of course, you want to do it the Right Way and just use an array:
Note that these arrays are zero-indexed, so with
x=1it printsstring2; if you wantstring1, you’ll needx=0.