Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to create dynamically a variable name as follows (simplified example):


SERIES1="a b c d e f g"
SERIES2="h i j k l m n"

# How to get this value contains $SERIES1 or $SERIES2
# depending on the value of $IDX
CURRENT=${SERIES\${IDX}} # doesn't work, just an example

If IDX=1 I'd expect to have


to display

a b c d e f g

and if IDX=2 to display

h i j k l m n

I will need to use it in a loop for an undetermined number of SERIES coming from another script.

EDIT Currently using sh as shell but if needed I can use a different one (even if it means I might need to convert a few things but it's ok)

My question is: How do I assign the desired series to CURRENT

What have I tried? The example above (that doesn't work) and other flavors like:



I am on the way to something:

eval echo $`echo "SERIES$IDX"`

This displays the correct series. However I can't find a way to assign it to CURRENT:

CURRENT=eval echo $`echo "SERIES$IDX"`

But I guess more digging and I'll find something. Any help appreciated though


Ok I found it:


display what I expect, so CURRENT has the right content.

share|improve this question

Thanks to this website (and probably others have similar answer...):


SERIES1="a b c d e f g"
SERIES2="h i j k l m n"


Now CURRENT holds the content of SERIES1. If I change IDX to 2 then I get SERIES2 content.

share|improve this answer

This isn't precisely what you want, but if you use bash instead of sh then you can use arrays:

SERIES[1]="a b c d e f g"
SERIES[2]="h i j k l m n"

share|improve this answer
Thank you. I'd take it as last option but I found a way in sh – JScoobyCed May 22 '13 at 9:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.