# Variable names within array call

**URL:** <https://community.unix.com/t/variable-names-within-array-call/228199>\
**Category:** Shell Programming and Scripting\
**Created:** [January 19, 2009, 3:39pm UTC](https://community.unix.com/t/variable-names-within-array-call/228199 "2009-01-19T15:39:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vockleya](https://community.unix.com/letter_avatar/vockleya/32/6_22734026db12803ebb3e059622ac3534.png) [@vockleya](https://community.unix.com/u/vockleya)\
**Post date:** [January 19, 2009, 3:39pm UTC](https://community.unix.com/t/variable-names-within-array-call/228199/1 "2009-01-19T15:39:08Z")

</div>

I am trying to write a piece of code that will call a value from an array. There are multiple arrays that I need to call data from. Only one array needs to be used based on the step within the program. The arrays have the names "cue\_0", "cue\_1", and so on.

I can't figure out how to call a value from an array based on the array number (the one after the underscore) and the position within the array. I have been able to get it working when not using a variable in the array name, but putting a variable within the array name makes it stop working. I get an error that says "bad substitution" about the line of code noted below when I replace the "0" with a variable.

The code below is the part of my script that I am having trouble with. Any help would be greatly appreciated.

```nohighlight
for i in `seq 0 23`; do
     let position=i*4+9
     tput cup 1 $position
     case ${cue_0[$i]} in # I want to replace the "0" in this line with a variable"
          0) printf "off" ;;
          1) printf "on" ;;
     esac
done

```

---

<div class="post-metadata">

**Author:** ![Annihilannic](https://community.unix.com/user_avatar/community.unix.com/annihilannic/32/4183_2.png) [@Annihilannic](https://community.unix.com/u/Annihilannic)\
**Post date:** [January 21, 2009, 11:48pm UTC](https://community.unix.com/t/variable-names-within-array-call/228199/2 "2009-01-21T23:48:40Z")

</div>

Assuming the variable containing the 0 is "var":

```nohighlight
for i in `seq 0 23`; do
     let position=i*4+9
     tput cup 1 $position
     eval temp=\${cue_${var}[\$i]}
     case $temp in # I want to replace the "0" in this line with a variable"
          0) printf "off" ;;
          1) printf "on" ;;
     esac
done

```

---

<div class="post-metadata">

**Author:** ![vockleya](https://community.unix.com/letter_avatar/vockleya/32/6_22734026db12803ebb3e059622ac3534.png) [@vockleya](https://community.unix.com/u/vockleya)\
**Post date:** [January 22, 2009, 9:03pm UTC](https://community.unix.com/t/variable-names-within-array-call/228199/3 "2009-01-22T21:03:44Z")

</div>

Thank you. This is just what I was looking for.
