title: Run a command for each element in an array from a file
body: <p>I have an AWS environment where I need the json config files of the security groups. I have thought about finding the <code>GroupID</code> and then creating file with just the ID's. From here I would like to pass the created file into an array and use the command;</p>
  
  <p><code>aws ec2 describe-security-groups --group-ids $&lt;name&gt; &gt; $&lt;name&gt;.json</code> to create <code>n</code> amount of json files. I have used another post <a href="https://unix.stackexchange.com/questions/70934/bash-reading-txt-file-and-storing-in-array">https://unix.stackexchange.com/questions/70934/bash-reading-txt-file-and-storing-in-array</a> to read the contents of the file into the array. What I need is to now use the above command to create the json files.</p>
  
  <p>I think it's done at <code>[[ ${a[$i-1]} = $name ]] &amp;&amp; echo "${a[$i]}"</code> but I'm not sure as I don't really understand the array..</p>
  
  <pre><code>#!/bin/bash
  
  # get security-group id's from aws and create a file
   aws ec2 describe-security-groups | grep -i groupid | sort -bdu &gt; sg-names-unsorted.txt
  
  # clear leading/trailing text so only sg's remain &amp; cleanup
    cat sg-names-unsorted.txt | sed 's/^[ \t]*//;s/[ \t]*$//' &gt; output.txt
    cat output.txt | sed 's/\"GroupId": "//;s/"\t*$//' &gt; sg-names.txt
    rm sg-names-unsorted.txt output.txt
  
   IFS=$'\n' a=($(cat sg-names.txt))
   for i in $(seq ${#a[*]}); do
      [[ ${a[$i-1]} = $name ]] &amp;&amp; echo "${a[$i]}"
  done
  
   #aws ec2 describe-security-groups --group-ids $name &gt; $name.json
  </code></pre>