Alex Rivera | Logout

Using a variable to refer to another variable in Bash

Asked 2010-04-14T02:53:39.710
27
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?

Edit
Report

1 Answer

3

Try this:

eval echo \$c$x

Like others said, it makes more sense to use array in this case.

answered 2010-04-25T05:23:29.670

Your Answer