title: Proper Quoting in Bash: Attach numbers stored in i to a
body: <p>I wanted to write a short shell script, which removes specified pages from a pdf. Maybe I'm doing that in a bit convoluted manner, but that is what I came up with so far: </p>
  
  <pre><code>#!/bin/bash
  #This is a script to remove a specified page from a specified pdf.
  set verbose
  
  s="A1-$(($2-1))"
  
  if [ n -ge 3 ]; then
        for i in 2..$#
        do      
              s+=A$(($($i)+1))-$(($($(($i+1)))-1))
        done 
  fi
  pdftk A="$1" cat $s A$(($($#)+1))-end output output.pdf
  </code></pre>
  
  <p>I know it's quite convoluted code and if you know about the working of pdftk, I would appreciate a hint to make it easier, but for now I just need to know how to substitute a variable into a variable name. E.g. if </p>
  
  <pre><code>i=2
  a2=3
  echo $a($i)
  </code></pre>
  
  <p>gave me <code>3</code>, that would be great, but it doesn't. How do I achieve this?</p>