title: How do you create an array of temporary files in bash?
body: <p>I need to have multiple temporary files. I decided that an array is best for that because I indeed to create 10 temporary files, use them and them remove the 10 files. From researching I've come up with this:</p>
  
  <pre class="lang-sh prettyprint-override"><code>declare -A my_array
  my_array=()
  
  for i in `seq -w 1 10`
  do
      my_array[$i]= $(mktemp /tmp/$i.XXXX)
  
  done
  
  #Do stuff with the files in the array
  
  for i in `seq -w 1 10`
  do
      rm my_array[$i]
  done
  </code></pre>
  
  <p>However, this gives me the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>./plot.sh: line 7: /tmp/01.PkUG: Permission denied 
  ./plot.sh: line 7: /tmp/02.eFNZ: Permission denied And so on...
  </code></pre>
  
  <p>I'm confused because when I create the 10 files without the loop it works fine, but is obviously very messy:</p>
  
  <pre class="lang-sh prettyprint-override"><code>tmpfile1=$(mktemp /tmp/data1.XXX)
  tmpfile2=$(mktemp /tmp/data2.XXX)
  And so on...
  
  #And then remove
  
  rm $tmpfile1
  rm $tmpfile2
  And so on....
  </code></pre>