See the Bash FAQ: How can I use variable variables (indirect variables, pointers, references) or associative arrays?
To quote their example:
realvariable=contents
ref=realvariable
echo "${!ref}" # prints the contents of the real variable
To show how this is useful for your example:
function get_c() { local tmp; tmp="c$x"; echo ${!tmp}; }
x=1
c1=string1
c2=string2
c3=string3
echo $(get_c)
If, of course, you want to do it the Right Way and just use an array:
c=( "string1" "string2" "string3" )
x=1
echo "${c[$x]}"
Note that these arrays are zero-indexed, so with x=1
it prints string2
; if you want string1
, you'll need x=0
.